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
diff --git a/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DistributedLeadershipManager.java b/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DistributedLeadershipManager.java
index 58fd3eb..1a659ef 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DistributedLeadershipManager.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DistributedLeadershipManager.java
@@ -255,17 +255,7 @@
if (!candidateList.remove(localNodeId)) {
return;
}
- boolean success = false;
- if (candidateList.isEmpty()) {
- if (candidateMap.remove(path, candidates.version())) {
- success = true;
- }
- } else {
- if (candidateMap.replace(path, candidates.version(), candidateList)) {
- success = true;
- }
- }
- if (success) {
+ if (candidateMap.replace(path, candidates.version(), candidateList)) {
Versioned<List<NodeId>> newCandidates = candidateMap.get(path);
notifyCandidateRemoved(path, candidates.version(), candidates.creationTime(), newCandidates);
} else {
@@ -366,20 +356,9 @@
final MutableBoolean updated = new MutableBoolean(false);
candidateBoard.compute(path, (k, current) -> {
- if (candidates != null) {
- if (current != null && current.epoch() < newInfo.epoch()) {
- updated.setTrue();
- if (candidates.value().isEmpty()) {
- return null;
- } else {
- return newInfo;
- }
- }
- } else {
- if (current != null && current.epoch() == oldEpoch) {
- updated.setTrue();
- return null;
- }
+ if (current != null && current.epoch() < newInfo.epoch()) {
+ updated.setTrue();
+ return newInfo;
}
return current;
});
@@ -471,11 +450,8 @@
});
} else if (eventType.equals(LeadershipEvent.Type.CANDIDATES_CHANGED)) {
candidateBoard.compute(topic, (k, currentInfo) -> {
- if (currentInfo == null || currentInfo.epoch() <= leadershipUpdate.epoch()) {
+ if (currentInfo == null || currentInfo.epoch() < leadershipUpdate.epoch()) {
updateAccepted.setTrue();
- if (leadershipUpdate.candidates().isEmpty()) {
- return null;
- }
return leadershipUpdate;
}
return currentInfo;