Search in sources :

Example 1 with CPGroup

use of com.hazelcast.cp.CPGroup in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_nonMetadataRaftGroupLosesMajority_then_itCanBeForceDestroyed.

@Test
public void when_nonMetadataRaftGroupLosesMajority_then_itCanBeForceDestroyed() throws ExecutionException, InterruptedException {
    instances = newInstances(5);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", 3);
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup("id").toCompletableFuture().get();
    assertNotNull(group);
    assertEquals(groupId, group.id());
    CPMember[] groupMembers = group.members().toArray(new CPMember[0]);
    assertTrueEventually(() -> {
        for (CPMember member : groupMembers) {
            HazelcastInstance instance = factory.getInstance(member.getAddress());
            assertNotNull(getRaftNode(instance, groupId));
        }
    });
    factory.getInstance(groupMembers[0].getAddress()).getLifecycleService().terminate();
    factory.getInstance(groupMembers[1].getAddress()).getLifecycleService().terminate();
    HazelcastInstance runningInstance = factory.getInstance(groupMembers[2].getAddress());
    getRaftService(runningInstance).forceDestroyCPGroup(groupId.getName()).get();
    group = getRaftService(runningInstance).getCPGroup(groupId).get();
    assertEquals(CPGroupStatus.DESTROYED, group.status());
    assertTrueEventually(() -> assertNull(getRaftNode(runningInstance, groupId)));
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with CPGroup

use of com.hazelcast.cp.CPGroup in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_raftGroupDestroyTriggered_then_raftGroupIsDestroyed.

@Test
public void when_raftGroupDestroyTriggered_then_raftGroupIsDestroyed() throws ExecutionException, InterruptedException {
    int metadataGroupSize = 3;
    int cpNodeCount = 5;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId = createNewRaftGroup(instances[0], "id", cpNodeCount);
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup("id").toCompletableFuture().get();
    assertNotNull(group);
    assertEquals(groupId, group.id());
    destroyRaftGroup(instances[0], groupId);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            assertNull(getRaftNode(instance, groupId));
        }
    });
    assertTrueEventually(() -> {
        CPGroup g = getRaftService(instances[0]).getCPGroup(groupId).get();
        assertEquals(CPGroupStatus.DESTROYED, g.status());
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with CPGroup

use of com.hazelcast.cp.CPGroup in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_memberIsShutdown_then_itIsRemovedFromRaftGroups.

@Test
public void when_memberIsShutdown_then_itIsRemovedFromRaftGroups() throws ExecutionException, InterruptedException {
    int cpNodeCount = 7;
    int metadataGroupSize = 5;
    int atomicLong1GroupSize = 3;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId1 = createNewRaftGroup(instances[0], "id1", atomicLong1GroupSize);
    CPGroupId groupId2 = createNewRaftGroup(instances[0], "id2", cpNodeCount);
    CPMember endpoint = findCommonEndpoint(instances[0], getMetadataGroupId(instances[0]), groupId1);
    assertNotNull(endpoint);
    RaftInvocationManager invocationService = null;
    HazelcastInstance aliveInstance = null;
    for (HazelcastInstance instance : instances) {
        if (!getAddress(instance).equals(endpoint.getAddress())) {
            aliveInstance = instance;
            invocationService = getRaftInvocationManager(instance);
            break;
        }
    }
    assertNotNull(invocationService);
    factory.getInstance(endpoint.getAddress()).shutdown();
    CPGroupId metadataGroupId = getMetadataGroupId(aliveInstance);
    InternalCompletableFuture<List<CPMember>> f1 = invocationService.query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
    List<CPMember> activeEndpoints = f1.get();
    assertThat(activeEndpoints, not(hasItem(endpoint)));
    InternalCompletableFuture<CPGroup> f2 = invocationService.query(metadataGroupId, new GetRaftGroupOp(metadataGroupId), LINEARIZABLE);
    InternalCompletableFuture<CPGroup> f3 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId1), LINEARIZABLE);
    InternalCompletableFuture<CPGroup> f4 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId2), LINEARIZABLE);
    CPGroup metadataGroup = f2.get();
    assertFalse(metadataGroup.members().contains(endpoint));
    assertEquals(metadataGroupSize, metadataGroup.members().size());
    CPGroup atomicLongGroup1 = f3.get();
    assertFalse(atomicLongGroup1.members().contains(endpoint));
    assertEquals(atomicLong1GroupSize, atomicLongGroup1.members().size());
    CPGroup atomicLongGroup2 = f4.get();
    assertFalse(atomicLongGroup2.members().contains(endpoint));
    assertEquals(cpNodeCount - 1, atomicLongGroup2.members().size());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with CPGroup

use of com.hazelcast.cp.CPGroup in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_nonReachableEndpointsExist_createRaftGroupPrefersReachableEndpoints.

@Test
public void when_nonReachableEndpointsExist_createRaftGroupPrefersReachableEndpoints() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(5);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            Collection<CPMemberInfo> raftMembers = getRaftService(instance).getMetadataGroupManager().getActiveMembers();
            assertFalse(raftMembers.isEmpty());
        }
    });
    CPMember endpoint3 = instances[3].getCPSubsystem().getLocalCPMember();
    CPMember endpoint4 = instances[4].getCPSubsystem().getLocalCPMember();
    instances[3].getLifecycleService().terminate();
    instances[4].getLifecycleService().terminate();
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    CPGroupId groupId3 = invocationManager.createRaftGroup("groupId3", 3).get();
    CPGroupId groupId4 = invocationManager.createRaftGroup("g4", 4).get();
    RaftNodeImpl leaderNode = waitAllForLeaderElection(Arrays.copyOf(instances, 3), getMetadataGroupId(instances[0]));
    HazelcastInstance leader = getInstance(leaderNode.getLocalMember());
    CPGroup group3 = queryRaftGroupLocally(leader, groupId3);
    assertNotNull(group3);
    assertThat(group3.members(), not(hasItem(endpoint3)));
    assertThat(group3.members(), not(hasItem(endpoint4)));
    CPGroup group4 = queryRaftGroupLocally(leader, groupId4);
    assertNotNull(group4);
    boolean b3 = group4.members().contains(endpoint3);
    boolean b4 = group4.members().contains(endpoint4);
    assertTrue(b3 ^ b4);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with CPGroup

use of com.hazelcast.cp.CPGroup in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterSnapshot_newMemberInstallsSnapshot.

@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterSnapshot_newMemberInstallsSnapshot() throws ExecutionException, InterruptedException {
    int nodeCount = 3;
    int commitIndexAdvanceCountToSnapshot = 50;
    Config config = createConfig(nodeCount, nodeCount);
    config.getCPSubsystemConfig().getRaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitIndexAdvanceCountToSnapshot);
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        instances[i] = factory.newHazelcastInstance(config);
    }
    assertClusterSizeEventually(nodeCount, instances);
    waitUntilCPDiscoveryCompleted(instances);
    instances[0].getCPSubsystem().getAtomicLong("long@group1").set(1);
    instances[0].getCPSubsystem().getAtomicLong("long@group2").set(2);
    for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
        getRaftInvocationManager(instances[0]).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
    }
    assertTrueEventually(() -> assertTrue(getSnapshotEntry(getLeaderNode(instances, getMetadataGroupId(instances[0]))).index() >= commitIndexAdvanceCountToSnapshot));
    for (int i = 0; i < 5; i++) {
        instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    }
    instances[0].shutdown();
    HazelcastInstance newInstance = factory.newHazelcastInstance(config);
    newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    CPGroup metadataGroup = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    CPGroup group1 = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group1").toCompletableFuture().get();
    CPGroup group2 = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group2").toCompletableFuture().get();
    List<CPMember> cpMembers = new ArrayList<>(newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get());
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(new HazelcastInstance[] { instances[1], instances[2], newInstance }, metadataGroup.id()));
        RaftNodeImpl raftNode = getRaftNode(newInstance, metadataGroup.id());
        assertNotNull(raftNode);
        assertEquals(commitIndex, getCommitIndex(raftNode));
        CPGroup m = queryRaftGroupLocally(newInstance, metadataGroup.id());
        CPGroup g1 = queryRaftGroupLocally(newInstance, group1.id());
        CPGroup g2 = queryRaftGroupLocally(newInstance, group2.id());
        assertNotNull(m);
        assertNotNull(g1);
        assertNotNull(g2);
        assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), m.members().toArray(new CPMember[0]));
        assertArrayEquals(group1.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
        assertArrayEquals(group2.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
        List<CPMemberInfo> activeMembers = new ArrayList<>(getRaftService(newInstance).getMetadataGroupManager().getActiveMembers());
        assertEquals(cpMembers, activeMembers);
    });
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

CPGroup (com.hazelcast.cp.CPGroup)23 Test (org.junit.Test)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)19 CPMember (com.hazelcast.cp.CPMember)17 CPGroupId (com.hazelcast.cp.CPGroupId)14 SlowTest (com.hazelcast.test.annotation.SlowTest)13 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)12 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 ArrayList (java.util.ArrayList)5 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)4 Config (com.hazelcast.config.Config)3 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)3 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)3 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)3 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)3 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)2 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)2 GetMembershipChangeScheduleOp (com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp)2