Streamline updating out-of-sync follower 85/21485/7
authorTom Pantelis <tpanteli@brocade.com>
Sat, 30 May 2015 03:27:33 +0000 (23:27 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 4 Jun 2015 18:50:43 +0000 (18:50 +0000)
commit6e4a2530fbd24f87b47a756bcc281cb825616e2a
tree1652923165fe4c454b0b2f7155e1e743b27f0ca7
parent2763c33336189a88b1c7ae1cc1c5311709610ee2
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>
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