Search in sources :

Example 1 with CountDownLatchService

use of com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService in project hazelcast by hazelcast.

the class AwaitOp method run.

@Override
public Object run(CPGroupId groupId, long commitIndex) {
    CountDownLatchService service = getService();
    AwaitInvocationKey key = new AwaitInvocationKey(commitIndex, invocationUid, callerAddress, callId);
    if (service.await(groupId, name, key, timeoutMillis)) {
        return true;
    }
    return timeoutMillis > 0 ? PostponedResponse.INSTANCE : false;
}
Also used : AwaitInvocationKey(com.hazelcast.cp.internal.datastructures.countdownlatch.AwaitInvocationKey) CountDownLatchService(com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService)

Example 2 with CountDownLatchService

use of com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService in project hazelcast by hazelcast.

the class CPSubsystemInfoCollector method forEachMetric.

@Override
public void forEachMetric(Node node, BiConsumer<PhoneHomeMetrics, String> metricsConsumer) {
    int cpMemberCount = node.getNodeEngine().getConfig().getCPSubsystemConfig().getCPMemberCount();
    boolean cpSubsystemEnabled = cpMemberCount != 0;
    metricsConsumer.accept(PhoneHomeMetrics.CP_SUBSYSTEM_ENABLED, String.valueOf(cpSubsystemEnabled));
    if (cpSubsystemEnabled) {
        metricsConsumer.accept(PhoneHomeMetrics.CP_MEMBERS_COUNT, String.valueOf(cpMemberCount));
        RaftService raftService = node.getNodeEngine().getService(RaftService.SERVICE_NAME);
        int groupsCount = raftService.getMetadataGroupManager().getGroupIds().size();
        metricsConsumer.accept(PhoneHomeMetrics.CP_GROUPS_COUNT, String.valueOf(groupsCount));
        SemaphoreService semaphoreService = node.getNodeEngine().getService(SemaphoreService.SERVICE_NAME);
        int semaphoresCount = semaphoreService.getTotalResourcesCount();
        metricsConsumer.accept(PhoneHomeMetrics.CP_SEMAPHORES_COUNT, String.valueOf(semaphoresCount));
        CountDownLatchService clService = node.getNodeEngine().getService(CountDownLatchService.SERVICE_NAME);
        int clCount = clService.getTotalResourcesCount();
        metricsConsumer.accept(PhoneHomeMetrics.CP_COUNTDOWN_LATCHES_COUNT, String.valueOf(clCount));
        LockService lockService = node.getNodeEngine().getService(LockService.SERVICE_NAME);
        int locksCount = lockService.getTotalResourcesCount();
        metricsConsumer.accept(PhoneHomeMetrics.CP_FENCED_LOCKS_COUNT, String.valueOf(locksCount));
        AtomicLongService atomicLongService = node.getNodeEngine().getService(AtomicLongService.SERVICE_NAME);
        int atomicLongsCount = atomicLongService.getAtomicValuesCount();
        metricsConsumer.accept(PhoneHomeMetrics.CP_ATOMIC_LONGS_COUNT, String.valueOf(atomicLongsCount));
        AtomicRefService atomicRefService = node.getNodeEngine().getService(AtomicRefService.SERVICE_NAME);
        int atomicRefsCount = atomicRefService.getAtomicValuesCount();
        metricsConsumer.accept(PhoneHomeMetrics.CP_ATOMIC_REFS_COUNT, String.valueOf(atomicRefsCount));
    }
}
Also used : SemaphoreService(com.hazelcast.cp.internal.datastructures.semaphore.SemaphoreService) LockService(com.hazelcast.cp.internal.datastructures.lock.LockService) RaftService(com.hazelcast.cp.internal.RaftService) AtomicLongService(com.hazelcast.cp.internal.datastructures.atomiclong.AtomicLongService) CountDownLatchService(com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService) AtomicRefService(com.hazelcast.cp.internal.datastructures.atomicref.AtomicRefService)

Example 3 with CountDownLatchService

use of com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService in project hazelcast by hazelcast.

the class CountDownLatchLongAwaitClientTest method when_awaitDurationIsLongerThanOperationTimeout_then_invocationFromClientWaits.

@Test
public void when_awaitDurationIsLongerThanOperationTimeout_then_invocationFromClientWaits() throws ExecutionException, InterruptedException {
    ICountDownLatch latch = client.getCPSubsystem().getCountDownLatch(proxyName);
    HazelcastInstance instance = getLeaderInstance(instances, groupId);
    latch.trySetCount(1);
    Future<Boolean> f = spawn(() -> latch.await(5, TimeUnit.MINUTES));
    assertTrueEventually(() -> {
        CountDownLatchService service = getNodeEngineImpl(instance).getService(CountDownLatchService.SERVICE_NAME);
        assertFalse(service.getLiveOperations(groupId).isEmpty());
    });
    assertTrueAllTheTime(() -> {
        CountDownLatchService service = getNodeEngineImpl(instance).getService(CountDownLatchService.SERVICE_NAME);
        assertFalse(service.getLiveOperations(groupId).isEmpty());
    }, callTimeoutSeconds + 5);
    latch.countDown();
    assertCompletesEventually(f);
    assertTrue(f.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatchService(com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CountDownLatchService (com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)1 RaftService (com.hazelcast.cp.internal.RaftService)1 AtomicLongService (com.hazelcast.cp.internal.datastructures.atomiclong.AtomicLongService)1 AtomicRefService (com.hazelcast.cp.internal.datastructures.atomicref.AtomicRefService)1 AwaitInvocationKey (com.hazelcast.cp.internal.datastructures.countdownlatch.AwaitInvocationKey)1 LockService (com.hazelcast.cp.internal.datastructures.lock.LockService)1 SemaphoreService (com.hazelcast.cp.internal.datastructures.semaphore.SemaphoreService)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1