Committed by
Gerrit Code Review
Bug fix for candidates cache for issue of writing the wrong version.
Change-Id: Ie6d9fe5e84f82ffe708f124ffdce30a9ca4900ab
Showing
1 changed file
with
20 additions
and
9 deletions
... | @@ -266,7 +266,8 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -266,7 +266,8 @@ public class DistributedLeadershipManager implements LeadershipService { |
266 | } | 266 | } |
267 | } | 267 | } |
268 | if (success) { | 268 | if (success) { |
269 | - notifyCandidateRemoved(path, candidateList, candidates.version(), candidates.creationTime()); | 269 | + Versioned<List<NodeId>> newCandidates = candidateMap.get(path); |
270 | + notifyCandidateRemoved(path, candidates.version(), candidates.creationTime(), newCandidates); | ||
270 | } else { | 271 | } else { |
271 | log.warn("Failed to withdraw from candidates list. Will retry"); | 272 | log.warn("Failed to withdraw from candidates list. Will retry"); |
272 | retryWithdraw(path); | 273 | retryWithdraw(path); |
... | @@ -358,23 +359,33 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -358,23 +359,33 @@ public class DistributedLeadershipManager implements LeadershipService { |
358 | } | 359 | } |
359 | 360 | ||
360 | private void notifyCandidateRemoved( | 361 | private void notifyCandidateRemoved( |
361 | - String path, List<NodeId> candidates, long epoch, long electedTime) { | 362 | + String path, long oldEpoch, long oldTime, Versioned<List<NodeId>> candidates) { |
362 | - Leadership newInfo = new Leadership(path, candidates, epoch, electedTime); | 363 | + Leadership newInfo = (candidates == null) |
364 | + ? new Leadership(path, ImmutableList.of(), oldEpoch, oldTime) | ||
365 | + : new Leadership(path, candidates.value(), candidates.version(), candidates.creationTime()); | ||
363 | final MutableBoolean updated = new MutableBoolean(false); | 366 | final MutableBoolean updated = new MutableBoolean(false); |
367 | + | ||
364 | candidateBoard.compute(path, (k, current) -> { | 368 | candidateBoard.compute(path, (k, current) -> { |
365 | - if (current != null && current.epoch() <= newInfo.epoch()) { | 369 | + if (candidates != null) { |
366 | - log.info("updating candidateboard with removal of {}", newInfo); | 370 | + if (current != null && current.epoch() < newInfo.epoch()) { |
367 | - updated.setTrue(); | 371 | + updated.setTrue(); |
368 | - if (candidates.isEmpty()) { | 372 | + if (candidates.value().isEmpty()) { |
373 | + return null; | ||
374 | + } else { | ||
375 | + return newInfo; | ||
376 | + } | ||
377 | + } | ||
378 | + } else { | ||
379 | + if (current != null && current.epoch() == oldEpoch) { | ||
380 | + updated.setTrue(); | ||
369 | return null; | 381 | return null; |
370 | - } else { | ||
371 | - return newInfo; | ||
372 | } | 382 | } |
373 | } | 383 | } |
374 | return current; | 384 | return current; |
375 | }); | 385 | }); |
376 | // maybe rethink types of candidates events | 386 | // maybe rethink types of candidates events |
377 | if (updated.booleanValue()) { | 387 | if (updated.booleanValue()) { |
388 | + log.debug("updated candidateboard with removal: {}", newInfo); | ||
378 | LeadershipEvent event = new LeadershipEvent(LeadershipEvent.Type.CANDIDATES_CHANGED, newInfo); | 389 | LeadershipEvent event = new LeadershipEvent(LeadershipEvent.Type.CANDIDATES_CHANGED, newInfo); |
379 | notifyPeers(event); | 390 | notifyPeers(event); |
380 | } | 391 | } | ... | ... |
-
Please register or login to post a comment