Search in sources :

Example 46 with CPMember

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

Example 47 with CPMember

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

the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterRestartAndSnapshot_newMemberInstallsSnapshot.

@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterRestartAndSnapshot_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);
    RaftGroupId initialMetadataGroupId = getMetadataGroupId(instances[0]);
    instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    HazelcastInstance newInstance1 = factory.newHazelcastInstance(config);
    HazelcastInstance newInstance2 = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, instances[0], newInstance1, newInstance2);
    instances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    RaftGroupId newMetadataGroupId = getRaftService(instances[0]).getMetadataGroupId();
    assertTrue(newMetadataGroupId.getSeed() > initialMetadataGroupId.getSeed());
    assertEquals(newMetadataGroupId.getSeed(), getRaftService(newInstance1).getMetadataGroupId().getSeed());
    assertEquals(newMetadataGroupId.getSeed(), getRaftService(newInstance2).getMetadataGroupId().getSeed());
    for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
        getRaftInvocationManager(instances[0]).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
    }
    assertTrueEventually(() -> {
        assertTrue(getSnapshotEntry(getRaftNode(instances[0], newMetadataGroupId)).index() >= commitIndexAdvanceCountToSnapshot);
        assertTrue(getSnapshotEntry(getRaftNode(newInstance1, newMetadataGroupId)).index() >= commitIndexAdvanceCountToSnapshot);
        assertTrue(getSnapshotEntry(getRaftNode(newInstance2, newMetadataGroupId)).index() >= commitIndexAdvanceCountToSnapshot);
    });
    instances[0].getCPSubsystem().getAtomicLong("long@group1").set(1);
    instances[0].getCPSubsystem().getAtomicLong("long@group2").set(2);
    instances[0].shutdown();
    HazelcastInstance newInstance3 = factory.newHazelcastInstance(config);
    newInstance3.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    CPGroup metadataGroup = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    CPGroup group1 = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group1").toCompletableFuture().get();
    CPGroup group2 = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group2").toCompletableFuture().get();
    List<CPMember> cpMembers = new ArrayList<>(newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get());
    HazelcastInstance[] newInstances = new HazelcastInstance[] { newInstance1, newInstance2, newInstance3 };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, newMetadataGroupId));
        for (HazelcastInstance instance : Arrays.asList(newInstance1, newInstance2, newInstance3)) {
            assertEquals(newMetadataGroupId.getSeed(), getMetadataGroupId(instance).getSeed());
            RaftNodeImpl raftNode = getRaftNode(instance, newMetadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup m = queryRaftGroupLocally(instance, metadataGroup.id());
            CPGroup g1 = queryRaftGroupLocally(instance, group1.id());
            CPGroup g2 = queryRaftGroupLocally(instance, 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(instance).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 48 with CPMember

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

the class CPMemberAddRemoveTest method testExpandRaftGroup.

@Test
public void testExpandRaftGroup() throws ExecutionException, InterruptedException, TimeoutException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    instances[0].shutdown();
    instances[3].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[1]);
    CPGroup group = instances[1].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    assertEquals(3, group.members().size());
    Collection<CPMember> members = group.members();
    assertTrue(members.contains(instances[3].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[3], metadataGroupId)));
}
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) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 49 with CPMember

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

the class CPMemberAddRemoveTest method testExpandMultipleRaftGroupsMultipleTimes.

@Test
public void testExpandMultipleRaftGroupsMultipleTimes() throws ExecutionException, InterruptedException, TimeoutException {
    HazelcastInstance[] instances = newInstances(5, 5, 2);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    CPSubsystemManagementService managementService = instances[6].getCPSubsystem().getCPSubsystemManagementService();
    String groupName = "group1";
    instances[0].getCPSubsystem().getAtomicLong("long1@" + groupName).set(5);
    CPGroup otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    CPGroupId groupId = otherGroup.id();
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), groupId);
    CPMember[] otherGroupMembers = otherGroup.members().toArray(new CPMember[0]);
    List<Address> shutdownAddresses = asList(otherGroupMembers[0].getAddress(), otherGroupMembers[1].getAddress());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    HazelcastInstance[] runningInstances = new HazelcastInstance[instances.length - shutdownAddresses.size()];
    for (int i = 0, j = 0; i < instances.length; i++) {
        HazelcastInstance instance = instances[i];
        if (shutdownAddresses.contains(getAddress(instance))) {
            instance.shutdown();
        } else {
            runningInstances[j++] = instance;
        }
    }
    CPGroup metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    assertEquals(4, metadataGroup.members().size());
    assertEquals(4, otherGroup.members().size());
    assertTrueEventually(() -> {
        assertNotNull(getRaftNode(instances[5], metadataGroupId));
        assertNotNull(getRaftNode(instances[5], groupId));
    });
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    assertEquals(5, metadataGroup.members().size());
    assertEquals(5, otherGroup.members().size());
    CPGroup metadataGroupRef = metadataGroup;
    CPGroup otherGroupRef = otherGroup;
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(runningInstances, metadataGroupId));
        assertNotNull(getRaftNode(instances[6], groupId));
        for (HazelcastInstance instance : asList(instances[5], instances[6])) {
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g1 = queryRaftGroupLocally(instance, metadataGroupId);
            CPGroup g2 = queryRaftGroupLocally(instance, otherGroupRef.id());
            assertNotNull(g1);
            assertNotNull(g2);
            assertArrayEquals(metadataGroupRef.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
            assertArrayEquals(otherGroupRef.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
        }
    });
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) 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) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 50 with CPMember

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

the class CPMemberAddRemoveTest method when_snapshotIsTakenWhileRemovingCPLeader_newMemberInstallsSnapshot.

@Test
public void when_snapshotIsTakenWhileRemovingCPLeader_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);
    HazelcastInstance leaderInstance = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
    // Specifically, RemoveCPMemberOp will be in snapshot but CompleteRaftGroupMembershipChangesOp will not.
    for (int i = 0; i < commitIndexAdvanceCountToSnapshot - 5; i++) {
        getRaftInvocationManager(leaderInstance).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.
    leaderInstance.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