Fix testLeaderAndFollowerEntityOwnersReassignedAfterShutdown failure 47/56847/4
authorTom Pantelis <tompantelis@gmail.com>
Thu, 11 May 2017 11:32:39 +0000 (07:32 -0400)
committerRobert Varga <nite@hq.sk>
Fri, 12 May 2017 14:52:32 +0000 (14:52 +0000)
14:19:15 Failed tests:
14:19:15   DistributedEntityOwnershipIntegrationTest.testLeaderAndFollowerEntityOwnersReassignedAfterShutdown:439->lambda$testLeaderAndFollowerEntityOwnersReassignedAfterShutdown$1:440 Raft state expected:<[Leader]> but was:<[Candidate]>

After the leader is shut down, member-2 is supposed to be elected leader but,
in this case, it didn't get the vote from member-5 b/c member-2 had not yet
received the MemberUp for member-5 and thus did not have its peer actor address.
So I made changes to ensure member data stores are ready and members are up.

I also saw a failure where member-3 or member5 didn't grant the vote for member-2
b/c it's last log index was greater. This can happen is member-2 didn't was a bit
behind when the leader was shut down. So I changes it to obtain the leader's last
index and verify the remaining follower's last log index is up-to-date.

Change-Id: Ib5ad2e135bb3809e1c62a432a029a5a56109190d
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehavior.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipIntegrationTest.java

index 0b428fe..e8c1b09 100644 (file)
@@ -167,7 +167,8 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior {
      */
     protected RaftActorBehavior requestVote(ActorRef sender, RequestVote requestVote) {
 
-        log.debug("{}: In requestVote:  {}", logName(), requestVote);
+        log.debug("{}: In requestVote:  {} - currentTerm: {}, votedFor: {}, lastIndex: {}, lastTerm: {}", logName(),
+                requestVote, currentTerm(), votedFor(), lastIndex(), lastTerm());
 
         boolean grantVote = canGrantVote(requestVote);
 
index 4855bae..aaf4bc2 100644 (file)
@@ -38,6 +38,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -292,6 +293,8 @@ public class DistributedEntityOwnershipIntegrationTest {
         follower1Node.configDataStore().waitTillReady();
         follower2Node.configDataStore().waitTillReady();
 
+        follower1Node.waitForMembersUp("member-1", "member-3");
+
         final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
         final DOMEntityOwnershipService follower1EntityOwnershipService =
                 newOwnershipService(follower1Node.configDataStore());
@@ -322,6 +325,18 @@ public class DistributedEntityOwnershipIntegrationTest {
         verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-1", "member-3");
         verifyOwner(leaderDistributedDataStore, ENTITY2, "member-1");
 
+        // Get the leader's lastIndex and verify followers are fully synced before shutting down the leader
+
+        AtomicLong leaderLastIndex = new AtomicLong();
+        MemberNode.verifyRaftState(leaderDistributedDataStore, ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> leaderLastIndex.set(raftState.getLastIndex()));
+
+        MemberNode.verifyRaftState(follower1Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> assertEquals("Last index", leaderLastIndex.get(), raftState.getLastIndex()));
+
+        MemberNode.verifyRaftState(follower2Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> assertEquals("Last index", leaderLastIndex.get(), raftState.getLastIndex()));
+
         // Shutdown the leader and verify its removed from the candidate list
 
         leaderNode.cleanup();
@@ -381,6 +396,11 @@ public class DistributedEntityOwnershipIntegrationTest {
         leaderDistributedDataStore.waitTillReady();
         follower1Node.configDataStore().waitTillReady();
         follower2Node.configDataStore().waitTillReady();
+        follower3Node.configDataStore().waitTillReady();
+        follower4Node.configDataStore().waitTillReady();
+
+        leaderNode.waitForMembersUp("member-2", "member-3", "member-4", "member-5");
+        follower1Node.waitForMembersUp("member-1", "member-3", "member-4", "member-5");
 
         final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
         final DOMEntityOwnershipService follower1EntityOwnershipService =
@@ -421,6 +441,20 @@ public class DistributedEntityOwnershipIntegrationTest {
         verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-1", "member-3", "member-4");
         verifyOwner(leaderDistributedDataStore, ENTITY2, "member-1");
 
+        // Get the leader's lastIndex and verify followers are fully synced before shutting down the leader
+        AtomicLong leaderLastIndex = new AtomicLong();
+        MemberNode.verifyRaftState(leaderDistributedDataStore, ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> leaderLastIndex.set(raftState.getLastIndex()));
+
+        MemberNode.verifyRaftState(follower1Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> assertEquals("Last index", leaderLastIndex.get(), raftState.getLastIndex()));
+
+        MemberNode.verifyRaftState(follower2Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> assertEquals("Last index", leaderLastIndex.get(), raftState.getLastIndex()));
+
+        MemberNode.verifyRaftState(follower4Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME,
+            raftState -> assertEquals("Last index", leaderLastIndex.get(), raftState.getLastIndex()));
+
         // Shutdown the leader and follower3
 
         leaderNode.cleanup();

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.