use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class ProxySessionManagerService method onShutdown.
@Override
public boolean onShutdown(long timeout, TimeUnit unit) {
ILogger logger = nodeEngine.getLogger(getClass());
Map<RaftGroupId, InternalCompletableFuture<Object>> futures = shutdown();
long remainingTimeNanos = unit.toNanos(timeout);
boolean successful = true;
while (remainingTimeNanos > 0 && futures.size() > 0) {
Iterator<Entry<RaftGroupId, InternalCompletableFuture<Object>>> it = futures.entrySet().iterator();
while (it.hasNext()) {
Entry<RaftGroupId, InternalCompletableFuture<Object>> entry = it.next();
RaftGroupId groupId = entry.getKey();
InternalCompletableFuture<Object> f = entry.getValue();
if (f.isDone()) {
it.remove();
try {
f.get();
logger.fine("Session closed for " + groupId);
} catch (Exception e) {
logger.warning("Close session failed for " + groupId, e);
successful = false;
}
}
}
try {
Thread.sleep(SHUTDOWN_TASK_PERIOD_IN_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
remainingTimeNanos -= MILLISECONDS.toNanos(SHUTDOWN_TASK_PERIOD_IN_MILLIS);
}
return successful && futures.isEmpty();
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedUnlockIsSuccessfulAfterLockedByAnotherEndpoint.
@Test(timeout = 300_000)
public void testRetriedUnlockIsSuccessfulAfterLockedByAnotherEndpoint() {
lock.lock();
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid = newUnsecureUUID();
invocationManager.invoke(groupId, new UnlockOp(objectName, sessionId, getThreadId(), invUid)).joinInternal();
lockByOtherThread();
invocationManager.invoke(groupId, new UnlockOp(objectName, sessionId, getThreadId(), invUid)).joinInternal();
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testExpiredAndRetriedTryLockRequestReceivesFailureResponse.
@Test(timeout = 300_000)
public void testExpiredAndRetriedTryLockRequestReceivesFailureResponse() {
final CountDownLatch unlockLatch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
assertOpenEventually(unlockLatch);
lock.unlock();
});
assertTrueEventually(() -> assertTrue(lock.isLocked()));
final RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
UUID invUid = newUnsecureUUID();
InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(5)));
long fence1 = f1.joinInternal();
assertEquals(INVALID_FENCE, fence1);
unlockLatch.countDown();
assertTrueEventually(() -> assertFalse(lock.isLocked()));
InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(5)));
long fence2 = f2.joinInternal();
assertEquals(INVALID_FENCE, fence2);
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedTryLockWithTimeoutDoesNotCancelPendingLockRequest.
@Test(timeout = 300_000)
public void testRetriedTryLockWithTimeoutDoesNotCancelPendingLockRequest() {
lockByOtherThread();
// there is a session id now
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid = newUnsecureUUID();
invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
assertTrueEventually(() -> {
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertNotNull(registry.getResourceOrNull(objectName));
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
RaftService raftService = getNodeEngineImpl(primaryInstance).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();
}
});
latch.await(60, SECONDS);
assertTrue(verified[0]);
});
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractFencedLockBasicTest method testReentrantTryLockWithTimeoutFails_whenSessionClosed.
@Test
public void testReentrantTryLockWithTimeoutFails_whenSessionClosed() throws ExecutionException, InterruptedException {
long fence = lock.lockAndGetFence();
assertValidFence(fence);
AbstractProxySessionManager sessionManager = getSessionManager(proxyInstance);
RaftGroupId groupId = (RaftGroupId) lock.getGroupId();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
closeSession(instances[0], groupId, sessionId);
assertTrueEventually(() -> assertNotEquals(sessionId, sessionManager.getSession(groupId)));
try {
lock.tryLock(1, TimeUnit.SECONDS);
} catch (LockOwnershipLostException ignored) {
}
}
Aggregations