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;
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)) { 258 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,21 +356,10 @@ public class DistributedLeadershipManager implements LeadershipService { ...@@ -366,21 +356,10 @@ 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) {
370 if (current != null && current.epoch() < newInfo.epoch()) { 359 if (current != null && current.epoch() < newInfo.epoch()) {
371 updated.setTrue(); 360 updated.setTrue();
372 - if (candidates.value().isEmpty()) {
373 - return null;
374 - } else {
375 return newInfo; 361 return newInfo;
376 } 362 }
377 - }
378 - } else {
379 - if (current != null && current.epoch() == oldEpoch) {
380 - updated.setTrue();
381 - return null;
382 - }
383 - }
384 return current; 363 return current;
385 }); 364 });
386 // maybe rethink types of candidates events 365 // maybe rethink types of candidates events
...@@ -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;
......