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();
}
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());
}
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);
}
});
}
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);
}
});
}
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);
}
Aggregations