Search in sources :

Example 1 with BiTuple

use of com.hazelcast.internal.util.BiTuple in project hazelcast by hazelcast.

the class RaftNodeImpl method tryRunQueries.

public boolean tryRunQueries() {
    QueryState queryState = state.leaderState().queryState();
    if (queryState.queryCount() == 0) {
        return false;
    }
    long commitIndex = state.commitIndex();
    if (!queryState.isMajorityAcked(commitIndex, state.majority())) {
        return true;
    }
    Collection<BiTuple<Object, InternalCompletableFuture>> operations = queryState.operations();
    if (logger.isFineEnabled()) {
        logger.fine("Running " + operations.size() + " queries at commit index: " + commitIndex + ", query round: " + queryState.queryRound());
    }
    for (BiTuple<Object, InternalCompletableFuture> t : operations) {
        runQuery(t.element1, t.element2);
    }
    queryState.reset();
    return false;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) QueryState(com.hazelcast.cp.internal.raft.impl.state.QueryState) BiTuple(com.hazelcast.internal.util.BiTuple)

Example 2 with BiTuple

use of com.hazelcast.internal.util.BiTuple in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testRetriedWaitKeysAreExpiredTogether.

@Test(timeout = 300_000)
public void testRetriedWaitKeysAreExpiredTogether() {
    CountDownLatch releaseLatch = new CountDownLatch(1);
    spawn(() -> {
        lock.lock();
        assertOpenEventually(releaseLatch);
        lock.unlock();
    });
    assertTrueEventually(() -> assertTrue(lock.isLocked()));
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    BiTuple[] lockWaitTimeoutKeyRef = new BiTuple[1];
    InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
    NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
    LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
    assertTrueEventually(() -> {
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
        assertEquals(1, waitTimeouts.size());
        lockWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
    });
    InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        RaftService raftService = nodeEngine.getService(RaftService.SERVICE_NAME);
        int partitionId = raftService.getCPGroupPartitionId(groupId);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        boolean[] verified = new boolean[1];
        CountDownLatch latch = new CountDownLatch(1);
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public int getPartitionId() {
                return partitionId;
            }

            @Override
            public void run() {
                Lock lock = registry.getResourceOrNull(objectName);
                Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
                verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
                latch.countDown();
            }
        });
        assertOpenEventually(latch);
        assertTrue(verified[0]);
    });
    RaftOp op = new ExpireWaitKeysOp(LockService.SERVICE_NAME, Collections.singletonList(lockWaitTimeoutKeyRef[0]));
    invocationManager.invoke(groupId, op).joinInternal();
    assertTrueEventually(() -> assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty()));
    releaseLatch.countDown();
    assertTrueEventually(() -> assertFalse(lock.isLocked()));
    long fence1 = f1.joinInternal();
    long fence2 = f2.joinInternal();
    assertInvalidFence(fence1);
    assertInvalidFence(fence2);
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RaftOp(com.hazelcast.cp.internal.RaftOp) CountDownLatch(java.util.concurrent.CountDownLatch) ExpireWaitKeysOp(com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) Map(java.util.Map) BiTuple(com.hazelcast.internal.util.BiTuple) Test(org.junit.Test)

Example 3 with BiTuple

use of com.hazelcast.internal.util.BiTuple in project hazelcast by hazelcast.

the class AbstractSemaphoreAdvancedTest method testRetriedWaitKeysAreExpiredTogether.

@Test
public void testRetriedWaitKeysAreExpiredTogether() {
    semaphore.init(1);
    CountDownLatch releaseLatch = new CountDownLatch(1);
    spawn(() -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        assertOpenEventually(releaseLatch);
        semaphore.release();
    });
    assertTrueEventually(() -> assertEquals(0, semaphore.availablePermits()));
    // there is a session id now
    RaftGroupId groupId = getGroupId();
    AbstractProxySessionManager sessionManager = getSessionManager();
    long sessionId = sessionManager.getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    UUID invUid = newUnsecureUUID();
    BiTuple[] acquireWaitTimeoutKeyRef = new BiTuple[1];
    InternalCompletableFuture<Boolean> f1 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
        SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
        assertEquals(1, waitTimeouts.size());
        acquireWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
    });
    InternalCompletableFuture<Boolean> f2 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
    assertTrueEventually(() -> {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
        RaftService raftService = getNodeEngineImpl(primaryInstance).getService(RaftService.SERVICE_NAME);
        int partitionId = raftService.getCPGroupPartitionId(groupId);
        SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        boolean[] verified = new boolean[1];
        CountDownLatch latch = new CountDownLatch(1);
        OperationServiceImpl operationService = nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public int getPartitionId() {
                return partitionId;
            }

            @Override
            public void run() {
                Semaphore semaphore = registry.getResourceOrNull(objectName);
                Map<Object, WaitKeyContainer<AcquireInvocationKey>> waitKeys = semaphore.getInternalWaitKeysMap();
                verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
                latch.countDown();
            }
        });
        assertOpenEventually(latch);
        assertTrue(verified[0]);
    });
    RaftOp op = new ExpireWaitKeysOp(SemaphoreService.SERVICE_NAME, Collections.singletonList(acquireWaitTimeoutKeyRef[0]));
    invokeRaftOp(groupId, op).joinInternal();
    assertTrueEventually(() -> {
        NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
        SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
        assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty());
    });
    releaseLatch.countDown();
    assertTrueEventually(() -> assertEquals(1, semaphore.availablePermits()));
    assertFalse(f1.joinInternal());
    assertFalse(f2.joinInternal());
}
Also used : RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ISemaphore(com.hazelcast.cp.ISemaphore) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RaftOp(com.hazelcast.cp.internal.RaftOp) CountDownLatch(java.util.concurrent.CountDownLatch) ExpireWaitKeysOp(com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp) AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) AcquirePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) Map(java.util.Map) BiTuple(com.hazelcast.internal.util.BiTuple) Test(org.junit.Test)

Example 4 with BiTuple

use of com.hazelcast.internal.util.BiTuple in project hazelcast by hazelcast.

the class HazelcastSqlOperatorTableTest method testNoOverride.

/**
 * Make sure there are no overrides for operators defined in the operator table.
 */
@Test
public void testNoOverride() {
    Map<BiTuple<String, SqlSyntax>, SqlOperator> map = new HashMap<>();
    for (SqlOperator operator : HazelcastSqlOperatorTable.instance().getOperatorList()) {
        BiTuple<String, SqlSyntax> key = BiTuple.of(operator.getName(), operator.getSyntax());
        SqlOperator oldOperator = map.put(key, operator);
        assertNull("Duplicate operator \"" + operator.getName(), oldOperator);
    }
}
Also used : HashMap(java.util.HashMap) SqlSyntax(org.apache.calcite.sql.SqlSyntax) SqlOperator(org.apache.calcite.sql.SqlOperator) BiTuple(com.hazelcast.internal.util.BiTuple) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

BiTuple (com.hazelcast.internal.util.BiTuple)4 Test (org.junit.Test)3 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)2 RaftOp (com.hazelcast.cp.internal.RaftOp)2 RaftService (com.hazelcast.cp.internal.RaftService)2 ExpireWaitKeysOp (com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp)2 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)2 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ISemaphore (com.hazelcast.cp.ISemaphore)1 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)1 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)1 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)1 QueryState (com.hazelcast.cp.internal.raft.impl.state.QueryState)1 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)1