Search in sources :

Example 1 with UnlockOperation

use of com.hazelcast.concurrent.lock.operations.UnlockOperation in project hazelcast by hazelcast.

the class LockProxySupport method unlock.

public void unlock(NodeEngine nodeEngine, Data key) {
    UnlockOperation operation = new UnlockOperation(namespace, key, getThreadId());
    InternalCompletableFuture<Number> f = invoke(nodeEngine, operation, key);
    f.join();
}
Also used : UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation)

Example 2 with UnlockOperation

use of com.hazelcast.concurrent.lock.operations.UnlockOperation in project hazelcast by hazelcast.

the class LockProxySupport method forceUnlock.

public void forceUnlock(NodeEngine nodeEngine, Data key) {
    UnlockOperation operation = new UnlockOperation(namespace, key, -1, true);
    InternalCompletableFuture<Number> f = invoke(nodeEngine, operation, key);
    f.join();
}
Also used : UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation)

Example 3 with UnlockOperation

use of com.hazelcast.concurrent.lock.operations.UnlockOperation in project hazelcast by hazelcast.

the class LockServiceImpl method createLockCleanupOperation.

private UnlockOperation createLockCleanupOperation(int partitionId, ObjectNamespace namespace, Data key, String uuid) {
    UnlockOperation op = new LocalLockCleanupOperation(namespace, key, uuid);
    op.setAsyncBackup(true);
    op.setNodeEngine(nodeEngine);
    op.setServiceName(SERVICE_NAME);
    op.setService(LockServiceImpl.this);
    op.setPartitionId(partitionId);
    op.setValidateTarget(false);
    return op;
}
Also used : LocalLockCleanupOperation(com.hazelcast.concurrent.lock.operations.LocalLockCleanupOperation) UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation)

Example 4 with UnlockOperation

use of com.hazelcast.concurrent.lock.operations.UnlockOperation in project hazelcast by hazelcast.

the class LockServiceImpl method cleanUpLock.

private void cleanUpLock(OperationService operationService, String uuid, int partitionId, LockStoreImpl lockStore) {
    Collection<LockResource> locks = lockStore.getLocks();
    for (LockResource lock : locks) {
        Data key = lock.getKey();
        if (uuid.equals(lock.getOwner()) && !lock.isTransactional()) {
            UnlockOperation op = createLockCleanupOperation(partitionId, lockStore.getNamespace(), key, uuid);
            // op will be executed on partition thread locally. Invocation is to handle retries.
            operationService.invokeOnTarget(SERVICE_NAME, op, nodeEngine.getThisAddress());
        }
        lockStore.cleanWaitersAndSignalsFor(key, uuid);
    }
}
Also used : UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) Data(com.hazelcast.nio.serialization.Data)

Example 5 with UnlockOperation

use of com.hazelcast.concurrent.lock.operations.UnlockOperation in project hazelcast by hazelcast.

the class Invocation_BlockingTest method sync_whenManyGettersAndLotsOfWaiting.

/**
     * Tests if the future on a blocking operation can be shared by multiple threads. This tests fails in 3.6 because
     * only 1 thread will be able to swap out CONTINUE_WAIT and all other threads will fail with an OperationTimeoutExcepyion
     */
@Test
public void sync_whenManyGettersAndLotsOfWaiting() throws Exception {
    int callTimeout = 10000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we execute an operation that stall the partition
    InternalOperationService opService = nodeEngine.getOperationService();
    // first we are going to lock
    int otherThreadId = 1;
    opService.createInvocationBuilder(null, new LockOperation(new InternalLockNamespace(key), nodeEngine.toData(key), otherThreadId, -1, -1), partitionId).setCallTimeout(callTimeout).invoke().join();
    // then we are going to send the invocation and share the future by many threads
    int thisThreadId = 2;
    final InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, new LockOperation(new InternalLockNamespace(key), nodeEngine.toData(key), thisThreadId, -1, -1), partitionId).setCallTimeout(callTimeout).invoke();
    // now we are going to do a get on the future by a whole bunch of threads
    final List<Future> futures = new LinkedList<Future>();
    for (int k = 0; k < 10; k++) {
        futures.add(spawn(new Callable() {

            @Override
            public Object call() throws Exception {
                return future.join();
            }
        }));
    }
    // lets do a very long wait so that the heartbeat/retrying mechanism have kicked in.
    // the lock remains locked; so the threads calling future.get remain blocked
    sleepMillis(callTimeout * 5);
    // unlocking the lock
    opService.createInvocationBuilder(null, new UnlockOperation(new InternalLockNamespace(key), nodeEngine.toData(key), otherThreadId), partitionId).setCallTimeout(callTimeout).invoke().join();
    // now the futures should all unblock
    for (Future f : futures) {
        assertEquals(Boolean.TRUE, f.get());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) Config(com.hazelcast.config.Config) UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

UnlockOperation (com.hazelcast.concurrent.lock.operations.UnlockOperation)6 InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)2 LockOperation (com.hazelcast.concurrent.lock.operations.LockOperation)2 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 LocalLockCleanupOperation (com.hazelcast.concurrent.lock.operations.LocalLockCleanupOperation)1 Data (com.hazelcast.nio.serialization.Data)1 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)1 LinkedList (java.util.LinkedList)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Future (java.util.concurrent.Future)1