Committed by
Gerrit Code Review
Eliminate possible redundant update when rearranging candidate order in leadership manager
Change-Id: Id76345ab827c4b6f55114f3afacdbc334092818a
Showing
1 changed file
with
4 additions
and
2 deletions
... | @@ -2,6 +2,7 @@ package org.onosproject.store.consistent.impl; | ... | @@ -2,6 +2,7 @@ package org.onosproject.store.consistent.impl; |
2 | 2 | ||
3 | import com.google.common.collect.ImmutableList; | 3 | import com.google.common.collect.ImmutableList; |
4 | import com.google.common.collect.ImmutableMap; | 4 | import com.google.common.collect.ImmutableMap; |
5 | +import com.google.common.collect.Iterables; | ||
5 | import com.google.common.collect.Lists; | 6 | import com.google.common.collect.Lists; |
6 | import com.google.common.collect.Maps; | 7 | import com.google.common.collect.Maps; |
7 | import com.google.common.collect.Sets; | 8 | import com.google.common.collect.Sets; |
... | @@ -350,8 +351,9 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -350,8 +351,9 @@ public class DistributedLeadershipManager implements LeadershipService { |
350 | @Override | 351 | @Override |
351 | public boolean makeTopCandidate(String path, NodeId nodeId) { | 352 | public boolean makeTopCandidate(String path, NodeId nodeId) { |
352 | Versioned<List<NodeId>> newCandidates = candidateMap.computeIf(path, | 353 | Versioned<List<NodeId>> newCandidates = candidateMap.computeIf(path, |
353 | - candidates -> (candidates != null && candidates.contains(nodeId)) || | 354 | + candidates -> candidates != null && |
354 | - (candidates != null && Objects.equals(nodeId, candidates.get(LEADER_CANDIDATE_POS))), | 355 | + candidates.contains(nodeId) && |
356 | + !nodeId.equals(Iterables.getFirst(candidates, null)), | ||
355 | (topic, candidates) -> { | 357 | (topic, candidates) -> { |
356 | List<NodeId> updatedCandidates = new ArrayList<>(candidates.size()); | 358 | List<NodeId> updatedCandidates = new ArrayList<>(candidates.size()); |
357 | updatedCandidates.add(nodeId); | 359 | updatedCandidates.add(nodeId); | ... | ... |
-
Please register or login to post a comment