Remove the leader's FollowerLogInformation on RemoveServer 02/33002/2
authorTom Pantelis <tpanteli@brocade.com>
Mon, 18 Jan 2016 09:03:58 +0000 (04:03 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 20 Jan 2016 19:33:15 +0000 (19:33 +0000)
On RemoveServer, if removing follower, we need to also remove the
FollowerLogInformation entry from the followerToLog map in
AbstractLeader. Also, if a snapshot was being installed, we should
cleanup the mapFollowerToSnapshot.

Change-Id: I37df57a82a1c79ce375e48127bafd661a2dfe2c6
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java

index 95269f6..db9088e 100644 (file)
@@ -574,7 +574,10 @@ class RaftActorServerConfigurationSupport {
 
         @Override
         public void initiate() {
-            raftContext.removePeer(getRemoveServerContext().getOperation().getServerId());
+            String serverId = getRemoveServerContext().getOperation().getServerId();
+            raftContext.removePeer(serverId);
+            ((AbstractLeader)raftActor.getCurrentBehavior()).removeFollower(serverId);
+
             persistNewServerConfiguration(getRemoveServerContext());
         }
     }
index 3c2dc66..54af075 100644 (file)
@@ -140,6 +140,7 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
 
     public void removeFollower(String followerId) {
         followerToLog.remove(followerId);
+        mapFollowerToSnapshot.remove(followerId);
     }
 
     public void updateMinReplicaCount() {
index 0025a6d..47b1413 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.assertNoneMatching;
 import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.clearMessages;
 import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectFirstMatching;
@@ -39,6 +40,7 @@ import org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSna
 import org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader;
 import org.opendaylight.controller.cluster.raft.behaviors.Follower;
 import org.opendaylight.controller.cluster.raft.behaviors.Leader;
+import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
 import org.opendaylight.controller.cluster.raft.messages.AddServer;
 import org.opendaylight.controller.cluster.raft.messages.AddServerReply;
 import org.opendaylight.controller.cluster.raft.messages.AppendEntries;
@@ -773,13 +775,16 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest {
 
         leaderActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef());
         RemoveServerReply removeServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"), RemoveServerReply.class);
-
         assertEquals("getStatus", ServerChangeStatus.OK, removeServerReply.getStatus());
 
         final ApplyState applyState = MessageCollectorActor.expectFirstMatching(leaderCollector, ApplyState.class);
         assertEquals(0L, applyState.getReplicatedLogEntry().getIndex());
         verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(LEADER_ID));
 
+        RaftActorBehavior currentBehavior = leaderActor.underlyingActor().getCurrentBehavior();
+        assertTrue("Expected Leader", currentBehavior instanceof Leader);
+        assertEquals("Follower ids size", 0, ((Leader)currentBehavior).getFollowerIds().size());
+
         MessageCollectorActor.expectFirstMatching(collector, ServerRemoved.class);
     }