Fix AppendEntry logic when prevLogIndex and prevLogTerm is -1 60/24360/4
authorMoiz Raja <moraja@cisco.com>
Mon, 13 Jul 2015 20:31:42 +0000 (13:31 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 24 Jul 2015 18:22:02 +0000 (18:22 +0000)
commit0efdc8e538815024cc54955be0b55ebec0321be6
tree3633cea025e7fefef16cde0bb12e765a16e49bf9
parenta6db8d8fcb55e6b9a7a2102c9ec0b7e8ba752b50
Fix AppendEntry logic when prevLogIndex and prevLogTerm is -1

When an AppendEntry arrives at a Follower with the prevLogIndex and
prevLogTerm = -1 the Follower will accept that append entry and add it
to the log. For a newly started Follower this can be problematic
because this will be the first entry in that Followers log and so
applying this entry to the Follower's state can end up corrupting the
state or cause failures in committing transactions.

To fix this we now verify if the replicatedToAllIndex is present in the
Followers log. If it is present then the log is considered in sync else
not.

Change-Id: I09bead430f1a4556182263de54846792668cd27c
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/Follower.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java