Remove PrimaryShardInfoFutureCache entry on UnreachableMember event 71/21571/2
authorTom Pantelis <tpanteli@brocade.com>
Sat, 30 May 2015 07:15:10 +0000 (03:15 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 1 Jun 2015 19:06:29 +0000 (19:06 +0000)
The ShardManager removes the PrimaryShardInfoFutureCache entry when
leadership changes. We should do the same for UnreachableMember events.

Change-Id: I9582450f1c319e6967f43aacd1b0dd668e2654d6
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
(cherry picked from commit fef4101b5a5b2f1d8e3b266662e36a37dd9151d0)

opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java

index d33576d..3241134 100644 (file)
@@ -477,6 +477,8 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering {
             if(leaderId != null && leaderId.contains(memberName)) {
                 LOG.debug("Marking Leader {} as unavailable.", leaderId);
                 info.setLeaderAvailable(false);
+
+                primaryShardInfoCache.remove(info.getShardName());
             }
         }
     }
index 1ffe387..33d5a2e 100644 (file)
@@ -2,6 +2,7 @@ package org.opendaylight.controller.cluster.datastore;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
@@ -54,6 +55,7 @@ import org.opendaylight.controller.cluster.datastore.messages.FindPrimary;
 import org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound;
 import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound;
 import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound;
+import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
 import org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound;
 import org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged;
 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
@@ -560,6 +562,9 @@ public class ShardManagerTest extends AbstractActorTest {
             String path = found.getPrimaryPath();
             assertTrue("Unexpected primary path " + path, path.contains("member-2-shard-default-config"));
 
+            primaryShardInfoCache.putSuccessful("default", new PrimaryShardInfo(system1.actorSelection(
+                    mockShardActor1.path()), Optional.<DataTree>absent()));
+
             shardManager1.underlyingActor().onReceiveCommand(MockClusterWrapper.
                 createUnreachableMember("member-2", "akka.tcp://cluster-test@127.0.0.1:2558"));
 
@@ -569,6 +574,8 @@ public class ShardManagerTest extends AbstractActorTest {
 
             expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
 
+            assertNull("Expected primaryShardInfoCache entry removed", primaryShardInfoCache.getIfPresent("default"));
+
             shardManager1.tell(new ShardLeaderStateChanged(memberId1, memberId1, Optional.of(mock(DataTree.class))),
                 mockShardActor1);
             shardManager1.tell(new RoleChangeNotification(memberId1,

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.