Ayaka Koshibe
Committed by Gerrit Code Review

Do not remove the topic from the CandidateMap even when the list of candidates

is empty. This makes the implementation and logic simpler and more consistent.

Change-Id: Ib55c5b9a020e147784cdf6156da2c47e70a3a6c2
...@@ -255,17 +255,7 @@ public class DistributedLeadershipManager implements LeadershipService { ...@@ -255,17 +255,7 @@ public class DistributedLeadershipManager implements LeadershipService {
255 if (!candidateList.remove(localNodeId)) { 255 if (!candidateList.remove(localNodeId)) {
256 return; 256 return;
257 } 257 }
258 - boolean success = false; 258 + if (candidateMap.replace(path, candidates.version(), candidateList)) {
259 - if (candidateList.isEmpty()) {
260 - if (candidateMap.remove(path, candidates.version())) {
261 - success = true;
262 - }
263 - } else {
264 - if (candidateMap.replace(path, candidates.version(), candidateList)) {
265 - success = true;
266 - }
267 - }
268 - if (success) {
269 Versioned<List<NodeId>> newCandidates = candidateMap.get(path); 259 Versioned<List<NodeId>> newCandidates = candidateMap.get(path);
270 notifyCandidateRemoved(path, candidates.version(), candidates.creationTime(), newCandidates); 260 notifyCandidateRemoved(path, candidates.version(), candidates.creationTime(), newCandidates);
271 } else { 261 } else {
...@@ -366,20 +356,9 @@ public class DistributedLeadershipManager implements LeadershipService { ...@@ -366,20 +356,9 @@ public class DistributedLeadershipManager implements LeadershipService {
366 final MutableBoolean updated = new MutableBoolean(false); 356 final MutableBoolean updated = new MutableBoolean(false);
367 357
368 candidateBoard.compute(path, (k, current) -> { 358 candidateBoard.compute(path, (k, current) -> {
369 - if (candidates != null) { 359 + if (current != null && current.epoch() < newInfo.epoch()) {
370 - if (current != null && current.epoch() < newInfo.epoch()) { 360 + updated.setTrue();
371 - updated.setTrue(); 361 + return newInfo;
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();
381 - return null;
382 - }
383 } 362 }
384 return current; 363 return current;
385 }); 364 });
...@@ -471,11 +450,8 @@ public class DistributedLeadershipManager implements LeadershipService { ...@@ -471,11 +450,8 @@ public class DistributedLeadershipManager implements LeadershipService {
471 }); 450 });
472 } else if (eventType.equals(LeadershipEvent.Type.CANDIDATES_CHANGED)) { 451 } else if (eventType.equals(LeadershipEvent.Type.CANDIDATES_CHANGED)) {
473 candidateBoard.compute(topic, (k, currentInfo) -> { 452 candidateBoard.compute(topic, (k, currentInfo) -> {
474 - if (currentInfo == null || currentInfo.epoch() <= leadershipUpdate.epoch()) { 453 + if (currentInfo == null || currentInfo.epoch() < leadershipUpdate.epoch()) {
475 updateAccepted.setTrue(); 454 updateAccepted.setTrue();
476 - if (leadershipUpdate.candidates().isEmpty()) {
477 - return null;
478 - }
479 return leadershipUpdate; 455 return leadershipUpdate;
480 } 456 }
481 return currentInfo; 457 return currentInfo;
......