Search in sources :

Example 6 with RaftGroupMembers

use of com.hazelcast.cp.internal.raft.impl.state.RaftGroupMembers in project hazelcast by hazelcast.

the class MembershipChangeTest method when_followerAppendsMultipleMembershipChangesAtOnce_then_itCommitsThemCorrectly.

@Test
public void when_followerAppendsMultipleMembershipChangesAtOnce_then_itCommitsThemCorrectly() throws ExecutionException, InterruptedException {
    RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(1000);
    group = newGroup(5, config);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    leader.replicate(new ApplyRaftRunnable("val")).get();
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            assertEquals(1L, getCommitIndex(follower));
        }
    });
    RaftNodeImpl slowFollower = followers[0];
    for (RaftNodeImpl follower : followers) {
        if (follower != slowFollower) {
            group.dropMessagesToMember(follower.getLocalMember(), follower.getLeader(), AppendSuccessResponse.class);
            group.dropMessagesToMember(follower.getLocalMember(), follower.getLeader(), AppendFailureResponse.class);
        }
    }
    RaftNodeImpl newRaftNode1 = group.createNewRaftNode();
    group.dropMessagesToMember(leader.getLocalMember(), newRaftNode1.getLocalMember(), AppendRequest.class);
    Future f1 = leader.replicateMembershipChange(newRaftNode1.getLocalMember(), MembershipChangeMode.ADD);
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            assertEquals(2L, getLastLogOrSnapshotEntry(follower).index());
        }
    });
    group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), AppendRequest.class);
    for (RaftNodeImpl follower : followers) {
        if (follower != slowFollower) {
            group.allowAllMessagesToMember(follower.getLocalMember(), leader.getLeader());
        }
    }
    f1.get();
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            if (follower != slowFollower) {
                assertEquals(6, getCommittedGroupMembers(follower).memberCount());
            } else {
                assertEquals(5, getCommittedGroupMembers(follower).memberCount());
                assertEquals(6, getLastGroupMembers(follower).memberCount());
            }
        }
    });
    RaftNodeImpl newRaftNode2 = group.createNewRaftNode();
    leader.replicateMembershipChange(newRaftNode2.getLocalMember(), MembershipChangeMode.ADD).get();
    group.allowAllMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember());
    group.allowAllMessagesToMember(slowFollower.getLocalMember(), leader.getLocalMember());
    group.allowAllMessagesToMember(leader.getLocalMember(), newRaftNode1.getLocalMember());
    RaftGroupMembers leaderCommittedGroupMembers = getCommittedGroupMembers(leader);
    assertTrueEventually(() -> {
        assertEquals(leaderCommittedGroupMembers.index(), getCommittedGroupMembers(slowFollower).index());
        assertEquals(leaderCommittedGroupMembers.index(), getCommittedGroupMembers(newRaftNode1).index());
        assertEquals(leaderCommittedGroupMembers.index(), getCommittedGroupMembers(newRaftNode2).index());
    });
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) RaftGroupMembers(com.hazelcast.cp.internal.raft.impl.state.RaftGroupMembers) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

RaftGroupMembers (com.hazelcast.cp.internal.raft.impl.state.RaftGroupMembers)6 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)4 RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)3 RaftDataService (com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)2 CPGroupId (com.hazelcast.cp.CPGroupId)1 CPMember (com.hazelcast.cp.CPMember)1 CPSubsystemException (com.hazelcast.cp.exception.CPSubsystemException)1 CannotReplicateException (com.hazelcast.cp.exception.CannotReplicateException)1 LeaderDemotedException (com.hazelcast.cp.exception.LeaderDemotedException)1 NotLeaderException (com.hazelcast.cp.exception.NotLeaderException)1 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)1 MembershipChangeMode (com.hazelcast.cp.internal.raft.MembershipChangeMode)1 QueryPolicy (com.hazelcast.cp.internal.raft.QueryPolicy)1 DestroyRaftGroupCmd (com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd)1 RaftGroupCmd (com.hazelcast.cp.internal.raft.command.RaftGroupCmd)1 MemberAlreadyExistsException (com.hazelcast.cp.internal.raft.exception.MemberAlreadyExistsException)1