Search in sources :

Example 41 with ApplyRaftRunnable

use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.

the class MembershipChangeTest method when_leaderLeaves_then_itCannotVoteForCommitOfMemberChange.

@Test
public void when_leaderLeaves_then_itCannotVoteForCommitOfMemberChange() throws ExecutionException, InterruptedException {
    RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(1000);
    group = newGroup(3, config);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    group.dropMessagesToMember(followers[0].getLocalMember(), leader.getLocalMember(), AppendSuccessResponse.class);
    leader.replicate(new ApplyRaftRunnable("val")).get();
    leader.replicateMembershipChange(leader.getLocalMember(), MembershipChangeMode.REMOVE);
    assertTrueAllTheTime(() -> assertEquals(1, getCommitIndex(leader)), 10);
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with ApplyRaftRunnable

use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.

the class MembershipChangeTest method when_newJoiningNodeFirstReceivesSnapshot_then_itInstallsSnapshot.

@Test
public void when_newJoiningNodeFirstReceivesSnapshot_then_itInstallsSnapshot() throws ExecutionException, InterruptedException {
    RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(5);
    group = newGroup(3, config);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    for (int i = 0; i < 4; i++) {
        leader.replicate(new ApplyRaftRunnable("val" + i)).get();
    }
    RaftNodeImpl newRaftNode = group.createNewRaftNode();
    group.dropMessagesToMember(leader.getLocalMember(), newRaftNode.getLocalMember(), AppendRequest.class);
    leader.replicateMembershipChange(newRaftNode.getLocalMember(), MembershipChangeMode.ADD).get();
    assertTrueEventually(() -> assertTrue(getSnapshotEntry(leader).index() > 0));
    group.resetAllRulesFrom(leader.getLocalMember());
    assertTrueEventually(() -> {
        assertEquals(getCommitIndex(leader), getCommitIndex(newRaftNode));
        assertEquals(getLastGroupMembers(leader).members(), getLastGroupMembers(newRaftNode).members());
        assertEquals(getLastGroupMembers(leader).members(), getCommittedGroupMembers(newRaftNode).members());
        RaftDataService service = group.getService(newRaftNode);
        assertEquals(4, service.size());
    });
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) RaftDataService(com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with ApplyRaftRunnable

use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.

the class MembershipChangeTest method when_leaderFailsWhileLeavingRaftGroup_othersCommitTheMemberChange.

@Test
public void when_leaderFailsWhileLeavingRaftGroup_othersCommitTheMemberChange() throws ExecutionException, InterruptedException {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    leader.replicate(new ApplyRaftRunnable("val")).get();
    for (RaftNodeImpl follower : followers) {
        group.dropMessagesToMember(follower.getLocalMember(), leader.getLocalMember(), AppendSuccessResponse.class);
        group.dropMessagesToMember(follower.getLocalMember(), leader.getLocalMember(), AppendFailureResponse.class);
    }
    leader.replicateMembershipChange(leader.getLocalMember(), MembershipChangeMode.REMOVE);
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            assertEquals(2, getLastLogOrSnapshotEntry(follower).index());
        }
    });
    group.terminateNode(leader.getLocalMember());
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            RaftEndpoint newLeaderEndpoint = getLeaderMember(follower);
            assertNotNull(newLeaderEndpoint);
            assertNotEquals(leader.getLocalMember(), newLeaderEndpoint);
        }
    });
    RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
    newLeader.replicate(new ApplyRaftRunnable("val2"));
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            assertFalse(getCommittedGroupMembers(follower).isKnownMember(leader.getLocalMember()));
        }
    });
}
Also used : ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with ApplyRaftRunnable

use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable 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)

Example 45 with ApplyRaftRunnable

use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.

the class DestroyRaftGroupTest method when_destroyOpIsTruncated_then_statusIsActive.

@Test
public void when_destroyOpIsTruncated_then_statusIsActive() throws ExecutionException, InterruptedException {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    group.dropMessagesToAll(leader.getLocalMember(), AppendRequest.class);
    leader.replicate(new DestroyRaftGroupCmd());
    group.split(leader.getLocalMember());
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : followers) {
            RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
            assertNotNull(leaderEndpoint);
            assertNotEquals(leader.getLocalMember(), leaderEndpoint);
        }
    });
    RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
    for (int i = 0; i < 10; i++) {
        newLeader.replicate(new ApplyRaftRunnable("val" + i)).get();
    }
    group.merge();
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : group.getNodes()) {
            assertEquals(RaftNodeStatus.ACTIVE, getStatus(raftNode));
        }
    });
}
Also used : DestroyRaftGroupCmd(com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)55 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)50 QuickTest (com.hazelcast.test.annotation.QuickTest)50 Test (org.junit.Test)50 RaftDataService (com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService)31 RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)23 LocalRaftGroupBuilder (com.hazelcast.cp.internal.raft.impl.testing.LocalRaftGroup.LocalRaftGroupBuilder)15 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)15 RestoredRaftState (com.hazelcast.cp.internal.raft.impl.persistence.RestoredRaftState)14 InMemoryRaftStateStore (com.hazelcast.cp.internal.raft.impl.testing.InMemoryRaftStateStore)10 Future (java.util.concurrent.Future)8 ArrayList (java.util.ArrayList)5 QueryRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.QueryRaftRunnable)4 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)4 RaftGroupMembers (com.hazelcast.cp.internal.raft.impl.state.RaftGroupMembers)4 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)3 CannotReplicateException (com.hazelcast.cp.exception.CannotReplicateException)2 LeaderDemotedException (com.hazelcast.cp.exception.LeaderDemotedException)2 DestroyRaftGroupCmd (com.hazelcast.cp.internal.raft.command.DestroyRaftGroupCmd)2 RaftUtil.getSnapshotEntry (com.hazelcast.cp.internal.raft.impl.RaftUtil.getSnapshotEntry)2