Search in sources :

Example 6 with CPMember

use of com.hazelcast.cp.CPMember 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 7 with CPMember

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

the class CPGroupRebalanceTest method getLeadershipsMap.

private Map<CPMember, Collection<CPGroupId>> getLeadershipsMap(HazelcastInstance instance, Collection<CPMember> members) {
    OperationServiceImpl operationService = getOperationService(instance);
    Map<CPMember, Collection<CPGroupId>> leaderships = new HashMap<>();
    for (CPMember member : members) {
        Collection<CPGroupId> groups = operationService.<Collection<CPGroupId>>invokeOnTarget(null, new GetLeadedGroupsOp(), member.getAddress()).join();
        leaderships.put(member, groups);
    }
    return leaderships;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) GetLeadedGroupsOp(com.hazelcast.cp.internal.operation.GetLeadedGroupsOp) HashMap(java.util.HashMap) Collection(java.util.Collection) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) CPMember(com.hazelcast.cp.CPMember)

Example 8 with CPMember

use of com.hazelcast.cp.CPMember 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 9 with CPMember

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

the class CPMemberAddRemoveTest method testExpandRaftGroupMultipleTimes.

@Test
public void testExpandRaftGroupMultipleTimes() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(5, 5, 3);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), metadataGroupId);
    instances[0].shutdown();
    instances[1].shutdown();
    instances[2].shutdown();
    CPSubsystemManagementService managementService = instances[3].getCPSubsystem().getCPSubsystemManagementService();
    CPGroup group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(2, group.members().size());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(3, group.members().size());
    Collection<CPMember> members = group.members();
    assertTrue(members.contains(instances[5].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(4, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[6].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[7].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(5, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[7].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    CPGroup metadataGroup = group;
    HazelcastInstance[] newInstances = { instances[3], instances[4], instances[5], instances[6], instances[7] };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, metadataGroupId));
        for (int i = 3; i < instances.length; i++) {
            HazelcastInstance instance = instances[i];
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g = queryRaftGroupLocally(instance, metadataGroupId);
            assertNotNull(g);
            assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), g.members().toArray(new CPMember[0]));
        }
    });
}
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) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 10 with CPMember

use of com.hazelcast.cp.CPMember 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)

Aggregations

CPMember (com.hazelcast.cp.CPMember)57 HazelcastInstance (com.hazelcast.core.HazelcastInstance)40 Test (org.junit.Test)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)27 CPGroup (com.hazelcast.cp.CPGroup)17 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)16 CPGroupId (com.hazelcast.cp.CPGroupId)14 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ArrayList (java.util.ArrayList)11 Config (com.hazelcast.config.Config)10 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)10 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)7 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)6 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 JsonValue (com.hazelcast.internal.json.JsonValue)4