Bug in AbstractLeader replication consensus 58/32858/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 13 Jan 2016 21:14:27 +0000 (16:14 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 18 Jan 2016 18:18:20 +0000 (18:18 +0000)
commit10ef5303f76d27271def9296d511916f26b6649c
treed6206cac3d123210ce11de8c5edb516deb8b77d4
parent5ba2066d922c470e11572a7ee95777caabe1f461
Bug in AbstractLeader replication consensus

I ran into an issue where the leader's commit index wasn't advancing
for new log entries even though consensus was reached. This scenario can
occur if the leader previously didn't get consensus and thus didn't commit
and apply a log entry and later regains leadership with a higher term.

The code in handleAppendEntriesReply doesn't update the commit index
if an entry's term doesn't match the current term. This behavior is correct
as per the raft paper - ยง5.4.1: "Raft never commits log entries from
previous terms by counting replicas". However the code also breaks out
of the loop and thus can never make progress on new entries in the current
term that reach consensus. This part is incorrect - as per raft "once an
entry from the current term is committed by counting replicas, then all
prior entries are committed indirectly". Therefore we need to continue
processing subsequent log entries in order to eventually make progress.

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