Search in sources :

Example 1 with GetMembershipChangeScheduleOp

use of com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRaftMemberNotPresentInAnyRaftGroupIsRemovedDirectlyAfterCrash.

@Test
public void testRaftMemberNotPresentInAnyRaftGroupIsRemovedDirectlyAfterCrash() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    HazelcastInstance master = instances[0];
    HazelcastInstance promoted = instances[instances.length - 1];
    promoted.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    CPMember promotedMember = promoted.getCPSubsystem().getLocalCPMember();
    promoted.getLifecycleService().terminate();
    master.getCPSubsystem().getCPSubsystemManagementService().removeCPMember(promotedMember.getUuid()).toCompletableFuture().get();
    MembershipChangeSchedule schedule = getRaftInvocationManager(master).<MembershipChangeSchedule>query(getMetadataGroupId(master), new GetMembershipChangeScheduleOp(), LINEARIZABLE).get();
    assertNull(schedule);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) GetMembershipChangeScheduleOp(com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with GetMembershipChangeScheduleOp

use of com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRaftMemberNotPresentInAnyRaftGroupIsRemovedDirectlyForGracefulShutdown.

@Test
public void testRaftMemberNotPresentInAnyRaftGroupIsRemovedDirectlyForGracefulShutdown() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    HazelcastInstance master = instances[0];
    HazelcastInstance promoted = instances[instances.length - 1];
    promoted.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    promoted.getLifecycleService().shutdown();
    MembershipChangeSchedule schedule = getRaftInvocationManager(master).<MembershipChangeSchedule>query(getMetadataGroupId(master), new GetMembershipChangeScheduleOp(), LINEARIZABLE).get();
    assertNull(schedule);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) GetMembershipChangeScheduleOp(com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with GetMembershipChangeScheduleOp

use of com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRemoveMemberFromMajorityLostRaftGroup.

@Test
public void testRemoveMemberFromMajorityLostRaftGroup() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup("test", 2).get();
    getRaftInvocationManager(instances[0]).invoke(groupId, new DummyOp()).get();
    RaftNodeImpl groupLeaderRaftNode = getLeaderNode(instances, groupId);
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId.getName()).toCompletableFuture().get();
    CPMember[] groupMembers = group.members().toArray(new CPMember[0]);
    CPMember crashedMember = groupMembers[0].getUuid().equals(groupLeaderRaftNode.getLocalMember().getUuid()) ? groupMembers[1] : groupMembers[0];
    HazelcastInstance runningInstance = (getAddress(instances[0])).equals(crashedMember.getAddress()) ? instances[1] : instances[0];
    RaftInvocationManager invocationManager = getRaftInvocationManager(runningInstance);
    factory.getInstance(crashedMember.getAddress()).getLifecycleService().terminate();
    // from now on, "test" group lost the majority
    // we triggered removal of the crashed member but we won't be able to commit to the "test" group
    CompletableFuture<Void> f = runningInstance.getCPSubsystem().getCPSubsystemManagementService().removeCPMember(crashedMember.getUuid()).toCompletableFuture();
    // wait until RaftCleanupHandler kicks in and appends ApplyRaftGroupMembersCmd to the leader of the "test" group
    assertTrueEventually(() -> assertTrue(getLastLogOrSnapshotEntry(groupLeaderRaftNode).operation() instanceof UpdateRaftGroupMembersCmd));
    // force-destroy the raft group.
    // Now, the pending membership change in the "test" group will fail and we will fix it in the metadata group.
    runningInstance.getCPSubsystem().getCPSubsystemManagementService().forceDestroyCPGroup(groupId.getName()).toCompletableFuture().get();
    f.get();
    MembershipChangeSchedule schedule = invocationManager.<MembershipChangeSchedule>query(getMetadataGroupId(runningInstance), new GetMembershipChangeScheduleOp(), LINEARIZABLE).get();
    assertNull(schedule);
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) GetMembershipChangeScheduleOp(com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp) CPMember(com.hazelcast.cp.CPMember) CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) UpdateRaftGroupMembersCmd(com.hazelcast.cp.internal.raft.impl.command.UpdateRaftGroupMembersCmd) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with GetMembershipChangeScheduleOp

use of com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRaftMemberIsRemovedForGracefulShutdown.

@Test
public void testRaftMemberIsRemovedForGracefulShutdown() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    CPMember shutdownCPMember = instances[0].getCPSubsystem().getLocalCPMember();
    instances[0].getLifecycleService().shutdown();
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[1]);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[1]);
    MembershipChangeSchedule schedule = invocationManager.<MembershipChangeSchedule>query(metadataGroupId, new GetMembershipChangeScheduleOp(), LINEARIZABLE).get();
    assertNull(schedule);
    CPGroup group = invocationManager.<CPGroup>invoke(metadataGroupId, new GetRaftGroupOp(metadataGroupId)).join();
    assertEquals(2, group.members().size());
    for (CPMember member : group.members()) {
        assertNotEquals(shutdownCPMember, member);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) GetMembershipChangeScheduleOp(com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 GetMembershipChangeScheduleOp (com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp)4 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 SlowTest (com.hazelcast.test.annotation.SlowTest)4 Test (org.junit.Test)4 CPMember (com.hazelcast.cp.CPMember)3 CPGroup (com.hazelcast.cp.CPGroup)2 CPGroupId (com.hazelcast.cp.CPGroupId)2 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)1 UpdateRaftGroupMembersCmd (com.hazelcast.cp.internal.raft.impl.command.UpdateRaftGroupMembersCmd)1 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)1