Committed by
Gerrit Code Review
Remove from leader board immediately on leader election withdraw.
This prevents some of the churn in the intent partitions due to partition manager working off inaccurate state. Change-Id: Ia324ea0273bc5d5858e378c05b45bafce6bda7e9
Showing
1 changed file
with
22 additions
and
18 deletions
1 | package org.onosproject.store.consistent.impl; | 1 | package org.onosproject.store.consistent.impl; |
2 | 2 | ||
3 | -import static org.onlab.util.Tools.groupedThreads; | 3 | +import com.google.common.collect.ImmutableMap; |
4 | -import static org.slf4j.LoggerFactory.getLogger; | 4 | +import com.google.common.collect.Maps; |
5 | -import static com.google.common.base.Preconditions.checkArgument; | 5 | +import com.google.common.collect.Sets; |
6 | - | ||
7 | -import java.util.Map; | ||
8 | -import java.util.Map.Entry; | ||
9 | -import java.util.Set; | ||
10 | -import java.util.concurrent.ExecutorService; | ||
11 | -import java.util.concurrent.Executors; | ||
12 | -import java.util.concurrent.ScheduledExecutorService; | ||
13 | -import java.util.concurrent.TimeUnit; | ||
14 | -import java.util.stream.Collectors; | ||
15 | - | ||
16 | import org.apache.felix.scr.annotations.Activate; | 6 | import org.apache.felix.scr.annotations.Activate; |
17 | import org.apache.felix.scr.annotations.Component; | 7 | import org.apache.felix.scr.annotations.Component; |
18 | import org.apache.felix.scr.annotations.Deactivate; | 8 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -41,9 +31,19 @@ import org.onosproject.store.service.StorageService; | ... | @@ -41,9 +31,19 @@ import org.onosproject.store.service.StorageService; |
41 | import org.onosproject.store.service.Versioned; | 31 | import org.onosproject.store.service.Versioned; |
42 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
43 | 33 | ||
44 | -import com.google.common.collect.ImmutableMap; | 34 | +import java.util.Map; |
45 | -import com.google.common.collect.Maps; | 35 | +import java.util.Map.Entry; |
46 | -import com.google.common.collect.Sets; | 36 | +import java.util.Objects; |
37 | +import java.util.Set; | ||
38 | +import java.util.concurrent.ExecutorService; | ||
39 | +import java.util.concurrent.Executors; | ||
40 | +import java.util.concurrent.ScheduledExecutorService; | ||
41 | +import java.util.concurrent.TimeUnit; | ||
42 | +import java.util.stream.Collectors; | ||
43 | + | ||
44 | +import static com.google.common.base.Preconditions.checkArgument; | ||
45 | +import static org.onlab.util.Tools.groupedThreads; | ||
46 | +import static org.slf4j.LoggerFactory.getLogger; | ||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Distributed Lock Manager implemented on top of ConsistentMap. | 49 | * Distributed Lock Manager implemented on top of ConsistentMap. |
... | @@ -199,8 +199,12 @@ public class DistributedLeadershipManager implements LeadershipService { | ... | @@ -199,8 +199,12 @@ public class DistributedLeadershipManager implements LeadershipService { |
199 | public void withdraw(String path) { | 199 | public void withdraw(String path) { |
200 | activeTopics.remove(path); | 200 | activeTopics.remove(path); |
201 | try { | 201 | try { |
202 | - if (lockMap.remove(path, localNodeId)) { | 202 | + Versioned<NodeId> leader = lockMap.get(path); |
203 | - log.info("Gave up leadership for {}", path); | 203 | + if (Objects.equals(leader.value(), localNodeId)) { |
204 | + if (lockMap.remove(path, leader.version())) { | ||
205 | + log.info("Gave up leadership for {}", path); | ||
206 | + notifyRemovedLeader(path, localNodeId, leader.version(), leader.creationTime()); | ||
207 | + } | ||
204 | } | 208 | } |
205 | // else we are not the current owner. | 209 | // else we are not the current owner. |
206 | } catch (Exception e) { | 210 | } catch (Exception e) { | ... | ... |
-
Please register or login to post a comment