Bug 7747: Reply to the leader before applying previous state 35/55735/1
authorTom Pantelis <tompantelis@gmail.com>
Thu, 20 Apr 2017 13:15:43 +0000 (09:15 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Thu, 20 Apr 2017 13:29:14 +0000 (13:29 +0000)
Applying state to the data tree can be expensive so the follower
should reply to the leader before applying any previous state so
as not to hold up leader consensus.

Change-Id: Ic92ae2ac30d72d6a401bdc36fda900a0a7fb21d3
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/Follower.java

index 30c1264ee89acf122c5244faa2c8e7c1fd815e7d..b512089692eed80da136bc8f7dfc2f5a2e10274c 100644 (file)
@@ -284,6 +284,18 @@ public class Follower extends AbstractRaftActorBehavior {
             log.debug("{}: Commit index set to {}", logName(), context.getCommitIndex());
         }
 
+        AppendEntriesReply reply = new AppendEntriesReply(context.getId(), currentTerm(), true,
+                lastIndex, lastTerm(), context.getPayloadVersion());
+
+        if (log.isTraceEnabled()) {
+            log.trace("{}: handleAppendEntries returning : {}", logName(), reply);
+        } else if (log.isDebugEnabled() && numLogEntries > 0) {
+            log.debug("{}: handleAppendEntries returning : {}", logName(), reply);
+        }
+
+        // Reply to the leader before applying any previous state so as not to hold up leader consensus.
+        sender.tell(reply, actor());
+
         // If commitIndex > lastApplied: increment lastApplied, apply
         // log[lastApplied] to state machine (ยง5.3)
         // check if there are any entries to be applied. last-applied can be equal to last-index
@@ -298,17 +310,6 @@ public class Follower extends AbstractRaftActorBehavior {
             applyLogToStateMachine(appendEntries.getLeaderCommit());
         }
 
-        AppendEntriesReply reply = new AppendEntriesReply(context.getId(), currentTerm(), true,
-            lastIndex, lastTerm(), context.getPayloadVersion());
-
-        if (log.isTraceEnabled()) {
-            log.trace("{}: handleAppendEntries returning : {}", logName(), reply);
-        } else if (log.isDebugEnabled() && numLogEntries > 0) {
-            log.debug("{}: handleAppendEntries returning : {}", logName(), reply);
-        }
-
-        sender.tell(reply, actor());
-
         if (!context.getSnapshotManager().isCapturing()) {
             super.performSnapshotWithoutCapture(appendEntries.getReplicatedToAllIndex());
         }