Remove PrimaryShardInfoFutureCache entry on UnreachableMember event 95/21495/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 16:21:52 +0000 (16:21 +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>
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 d33576d495fa66d2306ebb7d7378691269292e21..3241134492431c50a0f2bf9e165f7d43a9fb4631 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 1ffe387a199c3988e2ce214f31b9121167cfc79c..33d5a2ed981efbf4fb3260440866e339fbf9c949 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,