Search in sources :

Example 56 with CPGroupId

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

the class HttpGetCommandProcessor method handleGetCPGroupIds.

private void handleGetCPGroupIds(final HttpGetCommand command) {
    CompletionStage<Collection<CPGroupId>> f = getCpSubsystemManagementService().getCPGroupIds();
    f.whenCompleteAsync((groupIds, t) -> {
        if (t == null) {
            JsonArray arr = new JsonArray();
            for (CPGroupId groupId : groupIds) {
                arr.add(toJson(groupId));
            }
            prepareResponse(command, arr);
            textCommandService.sendResponse(command);
        } else {
            command.send500();
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) CPGroupId(com.hazelcast.cp.CPGroupId) Collection(java.util.Collection)

Example 57 with CPGroupId

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

the class CPGroupRebalanceTest method test.

@Test
public void test() throws Exception {
    int groupSize = 5;
    int leadershipsPerMember = 10;
    int groupCount = groupSize * leadershipsPerMember;
    HazelcastInstance[] instances = newInstances(groupSize, groupSize, 0);
    waitUntilCPDiscoveryCompleted(instances);
    Collection<CPGroupId> groupIds = new ArrayList<>(groupCount);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    for (int i = 0; i < groupCount; i++) {
        RaftGroupId groupId = invocationManager.createRaftGroup("group-" + i).joinInternal();
        groupIds.add(groupId);
    }
    HazelcastInstance metadataLeader = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
    Collection<CPMember> cpMembers = metadataLeader.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
    // Assert eventually since during the test
    // a long pause can cause leadership change unexpectedly.
    assertTrueEventually(() -> {
        // Wait for leader election all groups
        for (CPGroupId groupId : groupIds) {
            waitAllForLeaderElection(instances, groupId);
        }
        rebalanceLeaderships(metadataLeader);
        Map<CPMember, Collection<CPGroupId>> leadershipsMap = getLeadershipsMap(metadataLeader, cpMembers);
        for (Entry<CPMember, Collection<CPGroupId>> entry : leadershipsMap.entrySet()) {
            int count = entry.getValue().size();
            assertEquals(leadershipsString(leadershipsMap), leadershipsPerMember, count);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) CPMember(com.hazelcast.cp.CPMember) CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 58 with CPGroupId

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

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

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

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5