Search in sources :

Example 1 with CPGroupDestroyedException

use of com.hazelcast.cp.exception.CPGroupDestroyedException 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();
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) TriggerDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with CPGroupDestroyedException

use of com.hazelcast.cp.exception.CPGroupDestroyedException in project hazelcast by hazelcast.

the class RaftReplicateOp method run.

@Override
public final void run() {
    RaftService service = getService();
    RaftNode raftNode = service.getOrInitRaftNode(groupId);
    if (raftNode == null) {
        if (service.isRaftGroupDestroyed(groupId)) {
            sendResponse(new CPGroupDestroyedException(groupId));
        } else {
            sendResponse(new NotLeaderException(groupId, service.getLocalCPEndpoint(), null));
        }
        return;
    } else if (raftNode.getStatus() == RaftNodeStatus.STEPPED_DOWN) {
        sendResponse(new NotLeaderException(groupId, service.getLocalCPEndpoint(), null));
        getNodeEngine().getExecutionService().execute(CP_SUBSYSTEM_EXECUTOR, () -> service.stepDownRaftNode(groupId));
        return;
    }
    replicate(raftNode).whenCompleteAsync(this, CALLER_RUNS);
}
Also used : NotLeaderException(com.hazelcast.cp.exception.NotLeaderException) RaftService(com.hazelcast.cp.internal.RaftService) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode)

Example 3 with CPGroupDestroyedException

use of com.hazelcast.cp.exception.CPGroupDestroyedException in project hazelcast by hazelcast.

the class RaftQueryOp method run.

@Override
public final void run() {
    RaftService service = getService();
    RaftNode raftNode = service.getRaftNode(groupId);
    if (raftNode == null) {
        if (service.isRaftGroupDestroyed(groupId)) {
            sendResponse(new CPGroupDestroyedException(groupId));
        } else {
            sendResponse(new NotLeaderException(groupId, service.getLocalCPEndpoint(), null));
        }
        return;
    } else if (raftNode.getStatus() == RaftNodeStatus.STEPPED_DOWN) {
        sendResponse(new NotLeaderException(groupId, service.getLocalCPEndpoint(), null));
        getNodeEngine().getExecutionService().execute(CP_SUBSYSTEM_EXECUTOR, () -> service.stepDownRaftNode(groupId));
        return;
    }
    if (op instanceof RaftNodeAware) {
        ((RaftNodeAware) op).setRaftNode(raftNode);
    }
    raftNode.query(op, queryPolicy).whenCompleteAsync(this, CALLER_RUNS);
}
Also used : RaftNodeAware(com.hazelcast.cp.internal.RaftNodeAware) NotLeaderException(com.hazelcast.cp.exception.NotLeaderException) RaftService(com.hazelcast.cp.internal.RaftService) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode)

Example 4 with CPGroupDestroyedException

use of com.hazelcast.cp.exception.CPGroupDestroyedException in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testMetadataGroupReinitializationAfterLostMajority.

@Test
public void testMetadataGroupReinitializationAfterLostMajority() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    long groupIdSeed = getRaftService(instances[0]).getMetadataGroupManager().getGroupIdSeed();
    RaftGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup(CPGroup.DEFAULT_GROUP_NAME).get();
    IAtomicLong long1 = instances[0].getCPSubsystem().getAtomicLong("proxy");
    sleepAtLeastMillis(10);
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    assertClusterSizeEventually(2, instances[3]);
    HazelcastInstance[] newInstances = new HazelcastInstance[3];
    newInstances[0] = instances[0];
    newInstances[1] = instances[3];
    Config config = createConfig(3, 3);
    newInstances[2] = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, newInstances);
    newInstances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    waitUntilCPDiscoveryCompleted(newInstances);
    long newGroupIdSeed = getRaftService(newInstances[0]).getMetadataGroupManager().getGroupIdSeed();
    RaftGroupId newGroupId = getRaftInvocationManager(instances[0]).createRaftGroup(CPGroup.DEFAULT_GROUP_NAME).get();
    assertThat(newGroupIdSeed, greaterThan(groupIdSeed));
    assertThat(newGroupId.getSeed(), greaterThan(groupId.getSeed()));
    try {
        long1.incrementAndGet();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    IAtomicLong long2 = newInstances[2].getCPSubsystem().getAtomicLong("proxy");
    long2.incrementAndGet();
    assertTrueEventually(() -> {
        CPGroupSummary group = queryRaftGroupLocally(newInstances[2], getMetadataGroupId(newInstances[2]));
        assertNotNull(group);
        Collection<CPMember> endpoints = group.members();
        for (HazelcastInstance instance : newInstances) {
            Member localMember = instance.getCluster().getLocalMember();
            assertThat(new CPMemberInfo(localMember), isIn(endpoints));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) IAtomicLong(com.hazelcast.cp.IAtomicLong) Member(com.hazelcast.cluster.Member) CPMember(com.hazelcast.cp.CPMember) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 5 with CPGroupDestroyedException

use of com.hazelcast.cp.exception.CPGroupDestroyedException in project hazelcast by hazelcast.

the class AtomicRefBasicTest method testRecreate_afterGroupDestroy.

@Test
public void testRecreate_afterGroupDestroy() throws Exception {
    atomicRef.destroy();
    CPGroupId groupId = getGroupId(atomicRef);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
    assertTrueEventually(() -> {
        CPGroup group = invocationManager.<CPGroup>invoke(getMetadataGroupId(instances[0]), new GetRaftGroupOp(groupId)).join();
        assertEquals(CPGroupStatus.DESTROYED, group.status());
    });
    try {
        atomicRef.get();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    atomicRef = createAtomicRef(name);
    assertNotEquals(groupId, getGroupId(atomicRef));
    atomicRef.set("str1");
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) TriggerDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 Test (org.junit.Test)3 CPGroup (com.hazelcast.cp.CPGroup)2 CPGroupId (com.hazelcast.cp.CPGroupId)2 NotLeaderException (com.hazelcast.cp.exception.NotLeaderException)2 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)2 RaftService (com.hazelcast.cp.internal.RaftService)2 RaftNode (com.hazelcast.cp.internal.raft.impl.RaftNode)2 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)2 TriggerDestroyRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Member (com.hazelcast.cluster.Member)1 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 CPMember (com.hazelcast.cp.CPMember)1 IAtomicLong (com.hazelcast.cp.IAtomicLong)1 RaftNodeAware (com.hazelcast.cp.internal.RaftNodeAware)1 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)1 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)1