Bug in AbstractLeader replication consensus 48/32848/5
authorGary Wu <gary.wu1@huawei.com>
Fri, 15 Jan 2016 19:31:48 +0000 (11:31 -0800)
committerGary Wu <gary.wu1@huawei.com>
Wed, 20 Jan 2016 17:34:00 +0000 (17:34 +0000)
In determining whether to advance the commit index, only the voting
members should be counted in the replicatedCount.  There was a logic
error that instead caused it to be incorrectly based on whether the
AppendEntriesReply message as sent by a voting member.

This patch fixes the issue.

Change-Id: I6efb9574c39db608351297fc2552689d1ff77979
Signed-off-by: Gary Wu <gary.wu1@huawei.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

index 31ee9d2a7a61d3e2fa10fc6eb65544dbf7907b86..3c2dc66ee85a0ee5103cb66406cde0006d9aa353 100644 (file)
@@ -254,7 +254,8 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
             int replicatedCount = 1;
 
             for (FollowerLogInformation info : followerToLog.values()) {
-                if ((info.getMatchIndex() >= N) && (context.getPeerInfo(followerId).isVoting())) {
+                final PeerInfo peerInfo = context.getPeerInfo(info.getId());
+                if(info.getMatchIndex() >= N && (peerInfo != null && peerInfo.isVoting())) {
                     replicatedCount++;
                 }
             }
index 0733ad5479063b64ba4d23e5687f3df8fc0d34dc..26e5b7bffa320bfae8f098b55bd2c24061c3e127 100644 (file)
@@ -1999,7 +1999,7 @@ public class LeaderTest extends AbstractLeaderTest {
         MessageCollectorActor.assertNoneMatching(leaderActor, ApplyState.class, 500);
 
         // Send reply from the voting follower and verify consensus.
-        leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, 0, 1, (short)0));
+        leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, 1, 1, (short)0));
 
         MessageCollectorActor.expectFirstMatching(leaderActor, ApplyState.class);
     }