Committed by
Gerrit Code Review
Workaround for ONOS-1198
- check before unlocking to avoid Exception - mark field referenced from multiple threads Change-Id: I4da8450811aa69b9cc02a5e24178e7293d056aea
Showing
1 changed file
with
8 additions
and
4 deletions
... | @@ -18,6 +18,7 @@ package org.onosproject.store.cluster.impl; | ... | @@ -18,6 +18,7 @@ package org.onosproject.store.cluster.impl; |
18 | import com.google.common.collect.Maps; | 18 | import com.google.common.collect.Maps; |
19 | import com.hazelcast.config.TopicConfig; | 19 | import com.hazelcast.config.TopicConfig; |
20 | import com.hazelcast.core.IAtomicLong; | 20 | import com.hazelcast.core.IAtomicLong; |
21 | +import com.hazelcast.core.ILock; | ||
21 | 22 | ||
22 | import org.apache.felix.scr.annotations.Activate; | 23 | import org.apache.felix.scr.annotations.Activate; |
23 | import org.apache.felix.scr.annotations.Component; | 24 | import org.apache.felix.scr.annotations.Component; |
... | @@ -50,7 +51,6 @@ import java.util.Set; | ... | @@ -50,7 +51,6 @@ import java.util.Set; |
50 | import java.util.concurrent.ExecutorService; | 51 | import java.util.concurrent.ExecutorService; |
51 | import java.util.concurrent.Executors; | 52 | import java.util.concurrent.Executors; |
52 | import java.util.concurrent.Future; | 53 | import java.util.concurrent.Future; |
53 | -import java.util.concurrent.locks.Lock; | ||
54 | import java.util.stream.Collectors; | 54 | import java.util.stream.Collectors; |
55 | 55 | ||
56 | import static com.google.common.base.Preconditions.checkArgument; | 56 | import static com.google.common.base.Preconditions.checkArgument; |
... | @@ -247,8 +247,8 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -247,8 +247,8 @@ public class HazelcastLeadershipService implements LeadershipService { |
247 | // higher if the mastership has changed any times. | 247 | // higher if the mastership has changed any times. |
248 | private long myLastLeaderTerm = NO_TERM; | 248 | private long myLastLeaderTerm = NO_TERM; |
249 | 249 | ||
250 | - private NodeId leader; | 250 | + private volatile NodeId leader; |
251 | - private Lock leaderLock; | 251 | + private ILock leaderLock; |
252 | private Future<?> getLockFuture; | 252 | private Future<?> getLockFuture; |
253 | private Future<?> periodicProcessingFuture; | 253 | private Future<?> periodicProcessingFuture; |
254 | 254 | ||
... | @@ -427,6 +427,8 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -427,6 +427,8 @@ public class HazelcastLeadershipService implements LeadershipService { |
427 | long delta = System.currentTimeMillis() - | 427 | long delta = System.currentTimeMillis() - |
428 | lastLeadershipUpdateMs; | 428 | lastLeadershipUpdateMs; |
429 | if (delta > LEADERSHIP_REMOTE_TIMEOUT_MS) { | 429 | if (delta > LEADERSHIP_REMOTE_TIMEOUT_MS) { |
430 | + log.debug("Topic {} leader {} booted due to heartbeat timeout", | ||
431 | + topicName, leader); | ||
430 | leadershipEvent = new LeadershipEvent( | 432 | leadershipEvent = new LeadershipEvent( |
431 | LeadershipEvent.Type.LEADER_BOOTED, | 433 | LeadershipEvent.Type.LEADER_BOOTED, |
432 | new Leadership(topicName, leader, myLastLeaderTerm)); | 434 | new Leadership(topicName, leader, myLastLeaderTerm)); |
... | @@ -519,7 +521,9 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -519,7 +521,9 @@ public class HazelcastLeadershipService implements LeadershipService { |
519 | clusterService.getLocalNode().id(), | 521 | clusterService.getLocalNode().id(), |
520 | LEADERSHIP_EVENT_MESSAGE_SUBJECT, | 522 | LEADERSHIP_EVENT_MESSAGE_SUBJECT, |
521 | SERIALIZER.encode(leadershipEvent))); | 523 | SERIALIZER.encode(leadershipEvent))); |
522 | - leaderLock.unlock(); | 524 | + if (leaderLock.isLockedByCurrentThread()) { |
525 | + leaderLock.unlock(); | ||
526 | + } | ||
523 | } | 527 | } |
524 | } | 528 | } |
525 | } | 529 | } | ... | ... |
-
Please register or login to post a comment