Streamline updating out-of-sync follower 99/21899/1
authorTom Pantelis <tpanteli@brocade.com>
Sat, 30 May 2015 03:27:33 +0000 (23:27 -0400)
committerMoiz Raja <moraja@cisco.com>
Thu, 4 Jun 2015 18:51:29 +0000 (18:51 +0000)
commita564647b197ef00124b9ae6aa00578dd73e27aa1
tree2e3d40dcecefe6ec9576e79e5c746b910051b0ea
parenta54716c7a8c9a49a6b7b19eaedfbe522a2556b2b
Streamline updating out-of-sync follower

The first AppendEntries message a leader sends to a follower contains
the leader's entry at the current commit index as it doesn't know the
follower's next index yet. If the the previous index isn't present
in the follower's log, the follower sends back an unsuccessful reply. The
leader then decrements the prior index it just sent and sends the
next message. This continue's until the next index gets down to the
follower's last index (or -1 if the follower's log is empty). Then
it succeeds on the follower and the leader increments the next index
and sends the rest.

This results in at least twice the number of messages sent to sync the
follower. The follower sends back its lastIndex in the unsuccessful
responses so it seems to make sense for the leader to use that index
instead of decrementing what it thinks might be the next index. This
eliminates the excessive AppendEntries messages. However we should only
do this is the follower's last index is present in the leader's log and
the terms match. Otherwise we fall back to decrementing the index.

Change-Id: If49ed48e8c70cb87b06b48a5ed3e6b0bbb6efc36
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
(cherry picked from commit 6e4a2530fbd24f87b47a756bcc281cb825616e2a)
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/messages/AppendEntries.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java