Search in sources :

Example 21 with CPGroupId

use of com.hazelcast.cp.CPGroupId 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 22 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class CountDownLatchService method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    MetricDescriptor root = descriptor.withPrefix("cp.countdownlatch");
    for (CPGroupId groupId : getGroupIdSet()) {
        CountDownLatchRegistry registry = getRegistryOrNull(groupId);
        for (CountDownLatch latch : registry.getAllLatches()) {
            MetricDescriptor desc = root.copy().withDiscriminator("id", latch.getName() + "@" + groupId.getName()).withTag(CP_TAG_NAME, latch.getName()).withTag("group", groupId.getName());
            context.collect(desc.copy().withMetric("round"), latch.getRound());
            context.collect(desc.copy().withUnit(ProbeUnit.COUNT).withMetric("count"), latch.getCount());
            context.collect(desc.copy().withUnit(ProbeUnit.COUNT).withMetric("remaining"), latch.getRemainingCount());
        }
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ICountDownLatch(com.hazelcast.cp.ICountDownLatch)

Example 23 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class LockService method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    MetricDescriptor root = descriptor.withPrefix("cp.lock");
    for (CPGroupId groupId : getGroupIdSet()) {
        LockRegistry registry = getRegistryOrNull(groupId);
        for (Lock lock : registry.getAllLocks()) {
            MetricDescriptor desc = root.copy().withDiscriminator("id", lock.getName() + "@" + groupId.getName()).withTag(CP_TAG_NAME, lock.getName()).withTag("group", groupId.getName());
            context.collect(desc.copy().withUnit(ProbeUnit.COUNT).withMetric("acquireLimit"), lock.lockCountLimit());
            LockInvocationKey owner = lock.owner();
            int lockCount = lock.lockCount();
            // We may observe a partial update.
            if (owner != null && lockCount > 0) {
                context.collect(desc.copy().withUnit(ProbeUnit.COUNT).withMetric("lockCount"), lockCount);
                context.collect(desc.copy().withMetric("ownerSessionId"), owner.sessionId());
                context.collect(desc.copy().withTag("owner", owner.callerAddress().toString()).withMetric("owner"), 0);
            } else {
                context.collect(desc.copy().withUnit(ProbeUnit.COUNT).withMetric("lockCount"), 0);
            }
        }
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) FencedLock(com.hazelcast.cp.lock.FencedLock)

Example 24 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class LockService method createProxy.

@Override
public FencedLock createProxy(String proxyName) {
    proxyName = withoutDefaultGroupName(proxyName);
    while (true) {
        FencedLockProxy proxy = proxies.get(proxyName);
        if (proxy != null) {
            CPGroupId groupId = raftService.createRaftGroupForProxy(proxyName);
            if (!proxy.getGroupId().equals(groupId)) {
                proxies.remove(proxyName, proxy);
            } else {
                return proxy;
            }
        }
        proxy = doCreateProxy(proxyName);
        FencedLockProxy existing = proxies.putIfAbsent(proxyName, proxy);
        if (existing == null) {
            return proxy;
        }
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) FencedLockProxy(com.hazelcast.cp.internal.datastructures.lock.proxy.FencedLockProxy)

Example 25 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class GetAndAddMessageTask method processMessage.

@Override
protected void processMessage() {
    CPGroupId groupId = parameters.groupId;
    long delta = parameters.delta;
    RaftOp op = new GetAndAddOp(parameters.name, delta);
    if (delta == 0) {
        query(groupId, op, LINEARIZABLE);
    } else {
        invoke(groupId, op);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) RaftOp(com.hazelcast.cp.internal.RaftOp) GetAndAddOp(com.hazelcast.cp.internal.datastructures.atomiclong.operation.GetAndAddOp)

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5