BUG-8618: update sync status only after processing 41/59041/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Jun 2017 15:45:50 +0000 (17:45 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Thu, 15 Jun 2017 20:11:57 +0000 (20:11 +0000)
Since the commitIndex may move in chunks we really want to update
our sync status after we have gone through the AppendEntries message
so our commitIndex reflects the state after processing.

Change-Id: I49c72a21f8d9c3efb7ae9cc1b64276220057f2e2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit bdb818fbfc5f015ab14883348f170cca8ce79128)

opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/Follower.java

index c35de82..f8524b5 100644 (file)
@@ -157,7 +157,6 @@ public class Follower extends AbstractRaftActorBehavior {
         leaderId = appendEntries.getLeaderId();
         leaderPayloadVersion = appendEntries.getPayloadVersion();
 
-        updateInitialSyncStatus(appendEntries.getLeaderCommit(), appendEntries.getLeaderId());
         // First check if the logs are in sync or not
         long lastIndex = lastIndex();
 
@@ -169,7 +168,7 @@ public class Follower extends AbstractRaftActorBehavior {
                     lastTerm(), context.getPayloadVersion());
 
             log.info("{}: Follower is out-of-sync so sending negative reply: {}", logName(), reply);
-
+            updateInitialSyncStatus(appendEntries.getLeaderCommit(), appendEntries.getLeaderId());
             sender.tell(reply, actor());
             return this;
         }
@@ -217,6 +216,7 @@ public class Follower extends AbstractRaftActorBehavior {
                             // follower's log and state.
 
                             log.info("{}: Could not remove entries - sending reply to force snapshot", logName());
+                            updateInitialSyncStatus(appendEntries.getLeaderCommit(), appendEntries.getLeaderId());
                             sender.tell(new AppendEntriesReply(context.getId(), currentTerm(), false, lastIndex,
                                     lastTerm(), context.getPayloadVersion(), true), actor());
                             return this;
@@ -224,6 +224,7 @@ public class Follower extends AbstractRaftActorBehavior {
 
                         break;
                     } else {
+                        updateInitialSyncStatus(appendEntries.getLeaderCommit(), appendEntries.getLeaderId());
                         sender.tell(new AppendEntriesReply(context.getId(), currentTerm(), false, lastIndex,
                                 lastTerm(), context.getPayloadVersion(), true), actor());
                         return this;
@@ -294,6 +295,7 @@ public class Follower extends AbstractRaftActorBehavior {
         }
 
         // Reply to the leader before applying any previous state so as not to hold up leader consensus.
+        updateInitialSyncStatus(appendEntries.getLeaderCommit(), appendEntries.getLeaderId());
         sender.tell(reply, actor());
 
         // If commitIndex > lastApplied: increment lastApplied, apply

©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.