use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.
the class AbstractFencedLockProxy method lockAndGetFence.
@Override
public final long lockAndGetFence() {
long threadId = getThreadId();
UUID invocationUid = newUnsecureUUID();
for (; ; ) {
long sessionId = acquireSession();
verifyLockedSessionIdIfPresent(threadId, sessionId, true);
try {
long fence = doLock(sessionId, threadId, invocationUid).joinInternal();
if (fence != INVALID_FENCE) {
lockedSessionIds.put(threadId, sessionId);
return fence;
}
throw new LockAcquireLimitReachedException("Lock[" + objectName + "] reentrant lock limit is already reached!");
} catch (SessionExpiredException e) {
invalidateSession(sessionId);
verifyNoLockedSessionIdPresent(threadId);
} catch (WaitKeyCancelledException e) {
releaseSession(sessionId);
throw new IllegalMonitorStateException("Lock[" + objectName + "] not acquired because the lock call " + "on the CP group is cancelled, possibly because of another indeterminate call from the same thread.");
} catch (Throwable t) {
releaseSession(sessionId);
throw rethrow(t);
}
}
}
use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.
the class AbstractFencedLockProxy method tryLockAndGetFence.
@Override
public final long tryLockAndGetFence(long time, @Nonnull TimeUnit unit) {
checkNotNull(unit);
long threadId = getThreadId();
UUID invocationUid = newUnsecureUUID();
long timeoutMillis = Math.max(0, unit.toMillis(time));
long start;
for (; ; ) {
start = Clock.currentTimeMillis();
long sessionId = acquireSession();
verifyLockedSessionIdIfPresent(threadId, sessionId, true);
try {
long fence = doTryLock(sessionId, threadId, invocationUid, timeoutMillis).joinInternal();
if (fence != INVALID_FENCE) {
lockedSessionIds.put(threadId, sessionId);
} else {
releaseSession(sessionId);
}
return fence;
} catch (WaitKeyCancelledException e) {
releaseSession(sessionId);
return INVALID_FENCE;
} catch (SessionExpiredException e) {
invalidateSession(sessionId);
verifyNoLockedSessionIdPresent(threadId);
timeoutMillis -= (Clock.currentTimeMillis() - start);
if (timeoutMillis <= 0) {
return INVALID_FENCE;
}
} catch (Throwable t) {
releaseSession(sessionId);
throw rethrow(t);
}
}
}
use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method acquire.
@Override
public void acquire(int permits) {
checkPositive(permits, "Permits must be positive!");
long clusterWideThreadId = getOrCreateUniqueThreadId();
RaftOp op = new AcquirePermitsOp(objectName, NO_SESSION_ID, clusterWideThreadId, newUnsecureUUID(), permits, -1L);
try {
invocationManager.invoke(groupId, op).joinInternal();
} catch (WaitKeyCancelledException e) {
throw new IllegalStateException("Semaphore[" + objectName + "] not acquired because the acquire call " + "on the CP group is cancelled, possibly because of another indeterminate call from the same thread.");
}
}
use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testNewTryLockWithTimeoutCancelsPendingLockRequest.
@Test(timeout = 300_000)
public void testNewTryLockWithTimeoutCancelsPendingLockRequest() {
lockByOtherThread();
// there is a session id now
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid1 = newUnsecureUUID();
UUID invUid2 = newUnsecureUUID();
InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid1, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid2, MINUTES.toMillis(5)));
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testNewTryAcquireWithoutTimeoutCancelsPendingAcquireRequestsWhenNotAcquired.
@Test(timeout = 300_000)
public void testNewTryAcquireWithoutTimeoutCancelsPendingAcquireRequestsWhenNotAcquired() throws InterruptedException {
semaphore.init(1);
semaphore.acquire();
semaphore.release();
// if the session-aware semaphore is used, we guarantee that there is a session id now...
RaftGroupId groupId = getGroupId(semaphore);
long sessionId = getSessionId(proxyInstance, groupId);
long threadId = getThreadId(groupId);
UUID invUid1 = newUnsecureUUID();
UUID invUid2 = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid1, 2, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid2, 1, 0));
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
Aggregations