Search in sources :

Example 11 with CPGroup

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

the class AtomicLongBasicTest method testRecreate_afterGroupDestroy.

@Test
public void testRecreate_afterGroupDestroy() throws Exception {
    atomicLong.destroy();
    CPGroupId groupId = getGroupId(atomicLong);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
    assertTrueEventually(() -> {
        CPGroup group = invocationManager.<CPGroup>query(getMetadataGroupId(instances[0]), new GetRaftGroupOp(groupId), LINEARIZABLE).join();
        assertEquals(CPGroupStatus.DESTROYED, group.status());
    });
    try {
        atomicLong.incrementAndGet();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    atomicLong = createAtomicLong(name);
    CPGroupId newGroupId = getGroupId(atomicLong);
    assertNotEquals(groupId, newGroupId);
    atomicLong.incrementAndGet();
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) TriggerDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with CPGroup

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

the class RestCPSubsystemTest method test_reset.

@Test
public void test_reset() throws ExecutionException, InterruptedException, IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    CPGroup cpGroup1 = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(DEFAULT_GROUP_NAME).toCompletableFuture().get();
    sleepAtLeastMillis(10);
    ConnectionResponse response = new HTTPCommunicator(instance1).restart(clusterName, null);
    assertEquals(200, response.responseCode);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    CPGroup cpGroup2 = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(DEFAULT_GROUP_NAME).toCompletableFuture().get();
    RaftGroupId id1 = (RaftGroupId) cpGroup1.id();
    RaftGroupId id2 = (RaftGroupId) cpGroup2.id();
    assertTrue(id2.getSeed() > id1.getSeed());
}
Also used : CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 13 with CPGroup

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

the class HttpGetCommandProcessor method handleGetCPGroupByName.

private void handleGetCPGroupByName(final HttpGetCommand command) {
    String prefix = URI_CP_GROUPS_URL + "/";
    String groupName = command.getURI().substring(prefix.length()).trim();
    CompletionStage<CPGroup> f = getCpSubsystemManagementService().getCPGroup(groupName);
    f.whenCompleteAsync((group, t) -> {
        if (t == null) {
            if (group != null) {
                JsonObject json = new JsonObject();
                json.add("id", toJson(group.id())).add("status", group.status().name());
                JsonArray membersArr = new JsonArray();
                for (CPMember member : group.members()) {
                    membersArr.add(toJson(member));
                }
                json.add("members", membersArr);
                prepareResponse(command, json);
            } else {
                command.send404();
            }
            textCommandService.sendResponse(command);
        } else {
            command.send500();
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) CPGroup(com.hazelcast.cp.CPGroup) JsonObject(com.hazelcast.internal.json.JsonObject) CPMember(com.hazelcast.cp.CPMember)

Example 14 with CPGroup

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

the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterRestart_newMemberCommitsMetadataGroupLogEntries.

@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterRestart_newMemberCommitsMetadataGroupLogEntries() throws ExecutionException, InterruptedException {
    int nodeCount = 3;
    Config config = createConfig(nodeCount, nodeCount);
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        instances[i] = factory.newHazelcastInstance(config);
    }
    RaftGroupId initialMetadataGroupId = getMetadataGroupId(instances[0]);
    assertClusterSizeEventually(nodeCount, instances);
    waitUntilCPDiscoveryCompleted(instances);
    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());
    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, getMetadataGroupId(newInstance1)));
        for (HazelcastInstance instance : Arrays.asList(newInstance1, newInstance2, newInstance3)) {
            assertEquals(newMetadataGroupId.getSeed(), getMetadataGroupId(instance).getSeed());
            RaftNodeImpl raftNode = getRaftNode(instance, getMetadataGroupId(instance));
            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) 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 15 with CPGroup

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

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