Refresh candidate board from source on each election round + Disbale east-west s…
…ynchronization of candidate board Change-Id: Ie796e0ff0bdd2da834f70f24e98725a309e97787
Showing
1 changed file
with
12 additions
and
10 deletions
... | @@ -106,7 +106,6 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -106,7 +106,6 @@ public class DistributedLeadershipManager implements LeadershipService { |
106 | private static final int DELAY_BETWEEN_LEADER_LOCK_ATTEMPTS_SEC = 2; | 106 | private static final int DELAY_BETWEEN_LEADER_LOCK_ATTEMPTS_SEC = 2; |
107 | private static final int LEADERSHIP_STATUS_UPDATE_INTERVAL_SEC = 2; | 107 | private static final int LEADERSHIP_STATUS_UPDATE_INTERVAL_SEC = 2; |
108 | private static final int DELAY_BETWEEN_STALE_LEADERSHIP_PURGE_ATTEMPTS_SEC = 2; | 108 | private static final int DELAY_BETWEEN_STALE_LEADERSHIP_PURGE_ATTEMPTS_SEC = 2; |
109 | - private static final int LEADER_CANDIDATE_POS = 0; | ||
110 | 109 | ||
111 | private final AtomicBoolean staleLeadershipPurgeScheduled = new AtomicBoolean(false); | 110 | private final AtomicBoolean staleLeadershipPurgeScheduled = new AtomicBoolean(false); |
112 | 111 | ||
... | @@ -303,7 +302,7 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -303,7 +302,7 @@ public class DistributedLeadershipManager implements LeadershipService { |
303 | newCandidates.version(), | 302 | newCandidates.version(), |
304 | newCandidates.creationTime()))); | 303 | newCandidates.creationTime()))); |
305 | } else { | 304 | } else { |
306 | - log.warn("Failed to withdraw from candidates list. Will retry"); | 305 | + log.warn("Failed to withdraw from candidates list for {}. Will retry", path); |
307 | retryWithdraw(path, future); | 306 | retryWithdraw(path, future); |
308 | } | 307 | } |
309 | } catch (Exception e) { | 308 | } catch (Exception e) { |
... | @@ -403,10 +402,11 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -403,10 +402,11 @@ public class DistributedLeadershipManager implements LeadershipService { |
403 | try { | 402 | try { |
404 | candidateMap.entrySet().forEach(entry -> { | 403 | candidateMap.entrySet().forEach(entry -> { |
405 | String path = entry.getKey(); | 404 | String path = entry.getKey(); |
406 | - List<NodeId> candidates = entry.getValue().value(); | 405 | + Versioned<List<NodeId>> candidates = entry.getValue(); |
406 | + // for active topics, check if this node can become a leader (if it isn't already) | ||
407 | if (activeTopics.contains(path)) { | 407 | if (activeTopics.contains(path)) { |
408 | lockExecutor.submit(() -> { | 408 | lockExecutor.submit(() -> { |
409 | - Leadership leadership = electLeader(path, candidates); | 409 | + Leadership leadership = electLeader(path, candidates.value()); |
410 | if (leadership != null) { | 410 | if (leadership != null) { |
411 | CompletableFuture<Leadership> future = pendingFutures.remove(path); | 411 | CompletableFuture<Leadership> future = pendingFutures.remove(path); |
412 | if (future != null) { | 412 | if (future != null) { |
... | @@ -415,6 +415,14 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -415,6 +415,14 @@ public class DistributedLeadershipManager implements LeadershipService { |
415 | } | 415 | } |
416 | }); | 416 | }); |
417 | } | 417 | } |
418 | + // Raise a CANDIDATES_CHANGED event to force refresh local candidate board | ||
419 | + // and also to update local listeners. | ||
420 | + // Don't worry about duplicate events as they will be suppressed. | ||
421 | + onLeadershipEvent(new LeadershipEvent(LeadershipEvent.Type.CANDIDATES_CHANGED, | ||
422 | + new Leadership(path, | ||
423 | + candidates.value(), | ||
424 | + candidates.version(), | ||
425 | + candidates.creationTime()))); | ||
418 | }); | 426 | }); |
419 | } catch (Exception e) { | 427 | } catch (Exception e) { |
420 | log.debug("Failure electing leaders", e); | 428 | log.debug("Failure electing leaders", e); |
... | @@ -579,12 +587,6 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -579,12 +587,6 @@ public class DistributedLeadershipManager implements LeadershipService { |
579 | SERIALIZER::encode); | 587 | SERIALIZER::encode); |
580 | } | 588 | } |
581 | }); | 589 | }); |
582 | - candidateBoard.forEach((path, leadership) -> { | ||
583 | - LeadershipEvent event = new LeadershipEvent(LeadershipEvent.Type.CANDIDATES_CHANGED, leadership); | ||
584 | - clusterCommunicator.broadcast(event, | ||
585 | - LEADERSHIP_EVENT_MESSAGE_SUBJECT, | ||
586 | - SERIALIZER::encode); | ||
587 | - }); | ||
588 | } catch (Exception e) { | 590 | } catch (Exception e) { |
589 | log.debug("Failed to send leadership updates", e); | 591 | log.debug("Failed to send leadership updates", e); |
590 | } | 592 | } | ... | ... |
-
Please register or login to post a comment