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