use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_memberIsShutdown_then_itIsRemovedFromRaftGroups.
@Test
public void when_memberIsShutdown_then_itIsRemovedFromRaftGroups() throws ExecutionException, InterruptedException {
int cpNodeCount = 7;
int metadataGroupSize = 5;
int atomicLong1GroupSize = 3;
instances = newInstances(cpNodeCount, metadataGroupSize, 0);
CPGroupId groupId1 = createNewRaftGroup(instances[0], "id1", atomicLong1GroupSize);
CPGroupId groupId2 = createNewRaftGroup(instances[0], "id2", cpNodeCount);
CPMember endpoint = findCommonEndpoint(instances[0], getMetadataGroupId(instances[0]), groupId1);
assertNotNull(endpoint);
RaftInvocationManager invocationService = null;
HazelcastInstance aliveInstance = null;
for (HazelcastInstance instance : instances) {
if (!getAddress(instance).equals(endpoint.getAddress())) {
aliveInstance = instance;
invocationService = getRaftInvocationManager(instance);
break;
}
}
assertNotNull(invocationService);
factory.getInstance(endpoint.getAddress()).shutdown();
CPGroupId metadataGroupId = getMetadataGroupId(aliveInstance);
InternalCompletableFuture<List<CPMember>> f1 = invocationService.query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
List<CPMember> activeEndpoints = f1.get();
assertThat(activeEndpoints, not(hasItem(endpoint)));
InternalCompletableFuture<CPGroup> f2 = invocationService.query(metadataGroupId, new GetRaftGroupOp(metadataGroupId), LINEARIZABLE);
InternalCompletableFuture<CPGroup> f3 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId1), LINEARIZABLE);
InternalCompletableFuture<CPGroup> f4 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId2), LINEARIZABLE);
CPGroup metadataGroup = f2.get();
assertFalse(metadataGroup.members().contains(endpoint));
assertEquals(metadataGroupSize, metadataGroup.members().size());
CPGroup atomicLongGroup1 = f3.get();
assertFalse(atomicLongGroup1.members().contains(endpoint));
assertEquals(atomicLong1GroupSize, atomicLongGroup1.members().size());
CPGroup atomicLongGroup2 = f4.get();
assertFalse(atomicLongGroup2.members().contains(endpoint));
assertEquals(cpNodeCount - 1, atomicLongGroup2.members().size());
}
use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterSnapshot_newMemberInstallsSnapshot.
@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterSnapshot_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);
instances[0].getCPSubsystem().getAtomicLong("long@group1").set(1);
instances[0].getCPSubsystem().getAtomicLong("long@group2").set(2);
for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
getRaftInvocationManager(instances[0]).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
}
assertTrueEventually(() -> assertTrue(getSnapshotEntry(getLeaderNode(instances, getMetadataGroupId(instances[0]))).index() >= commitIndexAdvanceCountToSnapshot));
for (int i = 0; i < 5; i++) {
instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
}
instances[0].shutdown();
HazelcastInstance newInstance = factory.newHazelcastInstance(config);
newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
CPGroup metadataGroup = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
CPGroup group1 = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group1").toCompletableFuture().get();
CPGroup group2 = newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group2").toCompletableFuture().get();
List<CPMember> cpMembers = new ArrayList<>(newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get());
assertTrueEventually(() -> {
long commitIndex = getCommitIndex(getLeaderNode(new HazelcastInstance[] { instances[1], instances[2], newInstance }, metadataGroup.id()));
RaftNodeImpl raftNode = getRaftNode(newInstance, metadataGroup.id());
assertNotNull(raftNode);
assertEquals(commitIndex, getCommitIndex(raftNode));
CPGroup m = queryRaftGroupLocally(newInstance, metadataGroup.id());
CPGroup g1 = queryRaftGroupLocally(newInstance, group1.id());
CPGroup g2 = queryRaftGroupLocally(newInstance, 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(newInstance).getMetadataGroupManager().getActiveMembers());
assertEquals(cpMembers, activeMembers);
});
}
use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method when_snapshotIsTakenWhileRemovingCPMember_newMemberInstallsSnapshot.
@Test
public void when_snapshotIsTakenWhileRemovingCPMember_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);
// Specifically, RemoveCPMemberOp will be in snapshot but CompleteRaftGroupMembershipChangesOp will not.
for (int i = 0; i < commitIndexAdvanceCountToSnapshot - 5; i++) {
getRaftInvocationManager(instances[0]).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.
instances[0].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);
});
}
use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method testRaftInvocationsAfterMetadataGroupReinitialization.
@Test
public void testRaftInvocationsAfterMetadataGroupReinitialization() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = newInstances(3, 3, 1);
HazelcastInstance instance = instances[3];
instances[0].getLifecycleService().terminate();
instances[1].getLifecycleService().terminate();
instances[2].getLifecycleService().terminate();
assertClusterSizeEventually(1, instance);
instances = new HazelcastInstance[3];
instances[0] = instance;
Config config = createConfig(3, 3);
instances[1] = factory.newHazelcastInstance(config);
instances[2] = factory.newHazelcastInstance(config);
instance.getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
List<CPMemberInfo> newEndpoints = getRaftInvocationManager(instance).<List<CPMemberInfo>>query(getMetadataGroupId(instance), new GetActiveCPMembersOp(), LINEARIZABLE).get();
assertEquals(3, newEndpoints.size());
}
use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.
the class CPMemberAddRemoveTest method testResetRaftStateWhileMajorityIsReachable.
@Test
public void testResetRaftStateWhileMajorityIsReachable() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = newInstances(3);
RaftInvocationManager invocationManager = getRaftInvocationManager(instances[2]);
instances[0].getLifecycleService().terminate();
assertClusterSizeEventually(2, instances[1], instances[2]);
Config config = createConfig(3, 3);
instances[0] = factory.newHazelcastInstance(config);
instances[1].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
List<CPMemberInfo> newEndpoints = invocationManager.<List<CPMemberInfo>>query(getMetadataGroupId(instances[2]), new GetActiveCPMembersOp(), LINEARIZABLE).get();
for (HazelcastInstance instance : instances) {
assertTrue(newEndpoints.contains(new CPMemberInfo(instance.getCluster().getLocalMember())));
}
}
Aggregations