Search in sources :

Example 1 with ResetCPMemberOp

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;
}
Also used : Operation(com.hazelcast.spi.impl.operationservice.Operation) ResetCPMemberOp(com.hazelcast.cp.internal.operation.ResetCPMemberOp) ClusterService(com.hazelcast.internal.cluster.ClusterService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CPMember(com.hazelcast.cp.CPMember) Member(com.hazelcast.cluster.Member) BiConsumer(java.util.function.BiConsumer) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 2 with ResetCPMemberOp

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());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Config(com.hazelcast.config.Config) ResetCPMemberOp(com.hazelcast.cp.internal.operation.ResetCPMemberOp) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ResetCPMemberOp (com.hazelcast.cp.internal.operation.ResetCPMemberOp)2 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 CPMember (com.hazelcast.cp.CPMember)1 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 Test (org.junit.Test)1