Merge "Bug-2842:If an install snapshot is in progress, Follower should return immedia...
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / behaviors / Follower.java
index 618865cb88eb8877cdcfdcfb29208c80707c2c0f..bdd459ecffb3071c26e8d8d0bc53bacaab783f05 100644 (file)
@@ -96,6 +96,19 @@ public class Follower extends AbstractRaftActorBehavior {
         // to make it easier to read. Before refactoring ensure tests
         // cover the code properly
 
+        if (snapshotTracker != null) {
+            // if snapshot install is in progress, follower should just acknowledge append entries with a reply.
+            AppendEntriesReply reply = new AppendEntriesReply(context.getId(), currentTerm(), true,
+                    lastIndex(), lastTerm());
+
+            if(LOG.isDebugEnabled()) {
+                LOG.debug("{}: snapshot install is in progress, replying immediately with {}", logName(), reply);
+            }
+            sender.tell(reply, actor());
+
+            return this;
+        }
+
         // 1. Reply false if term < currentTerm (ยง5.1)
         // This is handled in the appendEntries method of the base class
 
@@ -352,7 +365,7 @@ public class Follower extends AbstractRaftActorBehavior {
         return snapshotTracker;
     }
 
-    private static class InitialSyncStatusTracker {
+    private class InitialSyncStatusTracker {
 
         private static final long INVALID_LOG_INDEX = -2L;
         private long initialLeaderCommit = INVALID_LOG_INDEX;
@@ -374,10 +387,10 @@ public class Follower extends AbstractRaftActorBehavior {
 
             if(!initialSyncUpDone){
                 if(initialLeaderCommit == INVALID_LOG_INDEX){
-                    actor.tell(new FollowerInitialSyncUpStatus(false), ActorRef.noSender());
+                    actor.tell(new FollowerInitialSyncUpStatus(false, getId()), ActorRef.noSender());
                     initialLeaderCommit = leaderCommit;
                 } else if(commitIndex >= initialLeaderCommit){
-                    actor.tell(new FollowerInitialSyncUpStatus(true), ActorRef.noSender());
+                    actor.tell(new FollowerInitialSyncUpStatus(true, getId()), ActorRef.noSender());
                     initialSyncUpDone = true;
                 }
             }