Bug 4850: Fix follower out-of-sync logic wrt replicatedToAllIndex 68/31968/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 30 Dec 2015 02:39:55 +0000 (21:39 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 5 Jan 2016 01:39:30 +0000 (01:39 +0000)
If the AppendEntries prevLogIndex is -1 and replicatedToAllIndex != -1,
it flags the follower as out-of-sync if there's no log entry for
replicatedToAllIndex. However replicatedToAllIndex may be in the
snapshot so I added a check for that as well. This fixes the issue
described in bug 4850.

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

index 5952dc087f8889e8607edf75dc2be77ee98b4424..57b1d92c726bb558ea95b1ac652f89043827bb46 100644 (file)
@@ -283,7 +283,8 @@ public class Follower extends AbstractRaftActorBehavior {
                     logName(), prevLogTerm, appendEntries.getPrevLogTerm());
         } else if(appendEntries.getPrevLogIndex() == -1 && appendEntries.getPrevLogTerm() == -1
                 && appendEntries.getReplicatedToAllIndex() != -1
-                && !isLogEntryPresent(appendEntries.getReplicatedToAllIndex())) {
+                && !isLogEntryPresent(appendEntries.getReplicatedToAllIndex())
+                && !context.getReplicatedLog().isInSnapshot(appendEntries.getReplicatedToAllIndex())) {
             // This append entry comes from a leader who has it's log aggressively trimmed and so does not have
             // the previous entry in it's in-memory journal
 
@@ -291,8 +292,9 @@ public class Follower extends AbstractRaftActorBehavior {
                     "{}: Cannot append entries because the replicatedToAllIndex {} does not appear to be in the in-memory journal",
                     logName(), appendEntries.getReplicatedToAllIndex());
         } else if(appendEntries.getPrevLogIndex() == -1 && appendEntries.getPrevLogTerm() == -1
-                && appendEntries.getReplicatedToAllIndex() != -1 && numLogEntries > 0 &&
-                !isLogEntryPresent(appendEntries.getEntries().get(0).getIndex() - 1)){
+                && appendEntries.getReplicatedToAllIndex() != -1 && numLogEntries > 0
+                && !isLogEntryPresent(appendEntries.getEntries().get(0).getIndex() - 1)
+                && !context.getReplicatedLog().isInSnapshot(appendEntries.getEntries().get(0).getIndex() - 1)) {
             LOG.debug(
                     "{}: Cannot append entries because the calculated previousIndex {} was not found in the in-memory journal",
                     logName(), appendEntries.getEntries().get(0).getIndex() - 1);