use of com.hazelcast.cp.internal.operation.ResetCPMemberOp in project hazelcast by hazelcast.
the class RaftService method resetCPSubsystem.
InternalCompletableFuture<Void> resetCPSubsystem() {
checkState(cpSubsystemEnabled, "CP Subsystem is not enabled!");
InternalCompletableFuture<Void> future = newCompletableFuture();
ClusterService clusterService = nodeEngine.getClusterService();
Collection<Member> members = clusterService.getMembers(NON_LOCAL_MEMBER_SELECTOR);
if (!clusterService.isMaster()) {
return complete(future, new IllegalStateException("Only master can reset CP Subsystem!"));
}
if (config.getCPMemberCount() > members.size() + 1) {
return complete(future, new IllegalStateException("Not enough cluster members to reset CP Subsystem! " + "Required: " + config.getCPMemberCount() + ", available: " + (members.size() + 1)));
}
BiConsumer<Void, Throwable> callback = new BiConsumer<Void, Throwable>() {
final AtomicInteger latch = new AtomicInteger(members.size());
volatile Throwable failure;
@Override
public void accept(Void aVoid, Throwable throwable) {
if (throwable == null) {
if (latch.decrementAndGet() == 0) {
if (failure == null) {
future.complete(null);
} else {
complete(future, failure);
}
}
} else {
failure = throwable;
if (latch.decrementAndGet() == 0) {
complete(future, throwable);
}
}
}
};
long seed = newSeed();
logger.warning("Resetting CP Subsystem with groupId seed: " + seed);
resetLocal(seed);
OperationServiceImpl operationService = nodeEngine.getOperationService();
for (Member member : members) {
Operation op = new ResetCPMemberOp(seed);
operationService.<Void>invokeOnTarget(SERVICE_NAME, op, member.getAddress()).whenCompleteAsync(callback);
}
return future;
}
use of com.hazelcast.cp.internal.operation.ResetCPMemberOp in project hazelcast by hazelcast.
the class MetadataRaftGroupTest method when_membersLeaveDuringDiscoveryAfterCPSubsystemRestart_then_discoveryIsCancelled.
@Test
public void when_membersLeaveDuringDiscoveryAfterCPSubsystemRestart_then_discoveryIsCancelled() throws ExecutionException, InterruptedException {
int nodeCount = 5;
Config config = createConfig(nodeCount, nodeCount);
HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
for (int i = 0; i < nodeCount; i++) {
instances[i] = factory.newHazelcastInstance(config);
}
waitUntilCPDiscoveryCompleted(instances);
instances[2].getLifecycleService().terminate();
instances[3].getLifecycleService().terminate();
instances[4].getLifecycleService().terminate();
instances[2] = factory.newHazelcastInstance(config);
instances[3] = factory.newHazelcastInstance(config);
// we are triggering the restart mechanism while there is a missing member already.
// the cp subsystem discovery won't be able to complete and we kill another member meanwhile
long seed = System.currentTimeMillis();
for (HazelcastInstance instance : Arrays.copyOf(instances, nodeCount - 1)) {
Address address = instance.getCluster().getLocalMember().getAddress();
getNodeEngineImpl(instance).getOperationService().invokeOnTarget(RaftService.SERVICE_NAME, new ResetCPMemberOp(seed), address).get();
}
// wait for the cp discovery process to start
sleepAtLeastSeconds(10);
instances[3].getLifecycleService().terminate();
assertTrueEventually(() -> {
for (int i = 0; i < 3; i++) {
assertTrue(getRaftService(instances[i]).getMetadataGroupManager().isDiscoveryCompleted());
assertNull(instances[i].getCPSubsystem().getLocalCPMember());
}
});
}
Aggregations