Source:
<code><START> public synchronized void verifyLeadership() { <END> boolean leadershipVerified = false; String leader = ""; Map<String, CompletableFuture<LogReplicationQueryLeaderShipResponse>> pendingLeadershipQueries = new HashMap<>(); if (!fsm.getRemoteLeader().isPresent()) { for (int i = 0; i < LEADERSHIP_RETRIES; i++) { log.info("Verify leadership on remote cluster, attempt={}", i); try { for (String node : fsm.getConnectedEndpoints()) { log.debug("Verify leadership status for node {}", node); CompletableFuture<LogReplicationQueryLeaderShipResponse> leadershipRequestCf = router.sendMessageAndGetCompletable(new CorfuMsg(CorfuMsgType.LOG_REPLICATION_QUERY_LEADERSHIP).setEpoch(0), node); pendingLeadershipQueries.put(node, leadershipRequestCf); } while (!leadershipVerified || pendingLeadershipQueries.size() != 0) { LogReplicationQueryLeaderShipResponse leadershipResponse = (LogReplicationQueryLeaderShipResponse) CompletableFuture.anyOf(pendingLeadershipQueries.values() .toArray(new CompletableFuture<?>[pendingLeadershipQueries.size()])).get(CorfuLogReplicationRuntime.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); if (leadershipResponse.isLeader()) { log.info("Leader for remote cluster, node={}", leadershipResponse.getEndpoint()); leader = leadershipResponse.getEndpoint(); fsm.setRemoteLeaderEndpoint(leader); leadershipVerified = true; pendingLeadershipQueries.clear(); break; } else { pendingLeadershipQueries.remove(leadershipResponse.getEndpoint()); } } if (leadershipVerified) { fsm.input(new LogReplicationRuntimeEvent(LogReplicationRuntimeEvent.LogReplicationRuntimeEventType.REMOTE_LEADER_FOUND, leader)); break; } } catch (Exception ex) { log.warn("Exception caught while verifying remote leader. Retry={}", i, ex); } } } }</code><technical_language>Is query leadership</technical_language>

Target:
public synchronized void verifyLeadership() { String leader = ""; Map<String, CompletableFuture<LogReplicationQueryLeaderShipResponse>> pendingLeadershipQueries = new HashMap<>(); if (!fsm.getRemoteLeader().isPresent()) { log.debug("Verify leader on remote cluster {}", fsm.getRemoteClusterId()); try { for (String node : fsm.getConnectedEndpoints()) { log.debug("Verify leadership status for node {}", node); CompletableFuture<LogReplicationQueryLeaderShipResponse> leadershipRequestCf = router.sendMessageAndGetCompletable(new CorfuMsg(CorfuMsgType.LOG_REPLICATION_QUERY_LEADERSHIP).setEpoch(0), node); pendingLeadershipQueries.put(node, leadershipRequestCf); } while (pendingLeadershipQueries.size() != 0) { LogReplicationQueryLeaderShipResponse leadershipResponse = (LogReplicationQueryLeaderShipResponse) CompletableFuture.anyOf(pendingLeadershipQueries.values() .toArray(new CompletableFuture<?>[pendingLeadershipQueries.size()])).get(CorfuLogReplicationRuntime.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); if (leadershipResponse.isLeader()) { log.info("Leader for remote cluster, node={}", leadershipResponse.getEndpoint()); leader = leadershipResponse.getEndpoint(); fsm.setRemoteLeaderEndpoint(leader); pendingLeadershipQueries.clear(); fsm.input(new LogReplicationRuntimeEvent(LogReplicationRuntimeEvent.LogReplicationRuntimeEventType.REMOTE_LEADER_FOUND, leader)); break; } else { log.debug("Leader is not "); pendingLeadershipQueries.remove(leadershipResponse.getEndpoint()); } } } catch (Exception ex) { log.warn("Exception caught while verifying remote leader.", ex); fsm.input(new LogReplicationRuntimeEvent(LogReplicationRuntimeEvent.LogReplicationRuntimeEventType.REMOTE_LEADER_NOT_FOUND, leader)); } } }