Search in sources :

Example 1 with GetActiveCPMembersOp

use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp 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 2 with GetActiveCPMembersOp

use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp 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)

Example 3 with GetActiveCPMembersOp

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

the class CPMemberAddRemoveTest method when_snapshotIsTakenWhileRemovingCPMember_newMemberInstallsSnapshot.

@Test
public void when_snapshotIsTakenWhileRemovingCPMember_newMemberInstallsSnapshot() throws Exception {
    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);
    // Specifically, RemoveCPMemberOp will be in snapshot but CompleteRaftGroupMembershipChangesOp will not.
    for (int i = 0; i < commitIndexAdvanceCountToSnapshot - 5; i++) {
        getRaftInvocationManager(instances[0]).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
    }
    // This will add 3 entries, RemoveCPMemberOp, ChangeRaftGroupMembersCmd and CompleteRaftGroupMembershipChangesOp.
    // RemoveCPMemberOp will be in snapshot but CompleteRaftGroupMembershipChangesOp will not be included.
    instances[0].shutdown();
    HazelcastInstance newInstance = factory.newHazelcastInstance(config);
    newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().join();
    List<CPMember> cpMembers = new ArrayList<>(newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().join());
    assertTrueEventually(() -> {
        RaftService service = getRaftService(newInstance);
        List<CPMemberInfo> activeMembers = new ArrayList<>(service.getMetadataGroupManager().getActiveMembers());
        assertEquals(cpMembers, activeMembers);
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with GetActiveCPMembersOp

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

the class CPMemberAddRemoveTest method testRaftInvocationsAfterMetadataGroupReinitialization.

@Test
public void testRaftInvocationsAfterMetadataGroupReinitialization() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    HazelcastInstance instance = instances[3];
    instances[0].getLifecycleService().terminate();
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    assertClusterSizeEventually(1, instance);
    instances = new HazelcastInstance[3];
    instances[0] = instance;
    Config config = createConfig(3, 3);
    instances[1] = factory.newHazelcastInstance(config);
    instances[2] = factory.newHazelcastInstance(config);
    instance.getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    List<CPMemberInfo> newEndpoints = getRaftInvocationManager(instance).<List<CPMemberInfo>>query(getMetadataGroupId(instance), new GetActiveCPMembersOp(), LINEARIZABLE).get();
    assertEquals(3, newEndpoints.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 5 with GetActiveCPMembersOp

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

the class CPMemberAddRemoveTest method testResetRaftStateWhileMajorityIsReachable.

@Test
public void testResetRaftStateWhileMajorityIsReachable() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[2]);
    instances[0].getLifecycleService().terminate();
    assertClusterSizeEventually(2, instances[1], instances[2]);
    Config config = createConfig(3, 3);
    instances[0] = factory.newHazelcastInstance(config);
    instances[1].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    List<CPMemberInfo> newEndpoints = invocationManager.<List<CPMemberInfo>>query(getMetadataGroupId(instances[2]), new GetActiveCPMembersOp(), LINEARIZABLE).get();
    for (HazelcastInstance instance : instances) {
        assertTrue(newEndpoints.contains(new CPMemberInfo(instance.getCluster().getLocalMember())));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 CPMember (com.hazelcast.cp.CPMember)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Config (com.hazelcast.config.Config)6 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 CPGroup (com.hazelcast.cp.CPGroup)4 CPGroupId (com.hazelcast.cp.CPGroupId)3 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)3 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)3 LINEARIZABLE (com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE)2 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)2 List (java.util.List)2 Member (com.hazelcast.cluster.Member)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 NON_LOCAL_MEMBER_SELECTOR (com.hazelcast.cluster.memberselector.MemberSelectors.NON_LOCAL_MEMBER_SELECTOR)1