use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.
the class DLockManagementDUnitTest method createLockServiceGrantor.
private void createLockServiceGrantor(final VM memberVM) {
memberVM.invoke("createLockServiceGrantor", () -> {
assertThat(DistributedLockService.getServiceNamed(LOCK_SERVICE_NAME)).isNull();
DLockService lockService = (DLockService) DistributedLockService.create(LOCK_SERVICE_NAME, this.managementTestRule.getCache().getDistributedSystem());
DistributedMember grantor = lockService.getLockGrantorId().getLockGrantorMember();
assertThat(grantor).isNotNull();
LockServiceMXBean lockServiceMXBean = awaitLockServiceMXBean(LOCK_SERVICE_NAME);
assertThat(lockServiceMXBean).isNotNull();
assertThat(lockServiceMXBean.isDistributed()).isTrue();
assertThat(lockServiceMXBean.getName()).isEqualTo(LOCK_SERVICE_NAME);
assertThat(lockServiceMXBean.isLockGrantor()).isTrue();
assertThat(lockServiceMXBean.fetchGrantorMember()).isEqualTo(this.managementTestRule.getDistributedMember().getId());
});
}
use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.
the class TXLockServiceDUnitTest method testTXRecoverGrantorMessageProcessor.
@Test
public void testTXRecoverGrantorMessageProcessor() throws Exception {
TXLockService.createDTLS();
checkDLockRecoverGrantorMessageProcessor();
/*
* call TXRecoverGrantorMessageProcessor.process directly to make sure that correct behavior
* occurs
*/
// get txLock and hold it
final Set participants = Collections.EMPTY_SET;
final List regionLockReqs = new ArrayList();
regionLockReqs.add(new TXRegionLockRequestImpl("/testTXRecoverGrantorMessageProcessor", new HashSet(Arrays.asList(new String[] { "KEY-1", "KEY-2", "KEY-3", "KEY-4" }))));
TXLockService dtls = TXLockService.getDTLS();
TXLockId txLockId = dtls.txLock(regionLockReqs, participants);
// async call TXRecoverGrantorMessageProcessor.process
final DLockService dlock = ((TXLockServiceImpl) dtls).getInternalDistributedLockService();
final TestDLockRecoverGrantorProcessor testProc = new TestDLockRecoverGrantorProcessor(dlock.getDistributionManager(), Collections.EMPTY_SET);
assertEquals("No valid processorId", true, testProc.getProcessorId() > -1);
final DLockRecoverGrantorProcessor.DLockRecoverGrantorMessage msg = new DLockRecoverGrantorProcessor.DLockRecoverGrantorMessage();
msg.setServiceName(dlock.getName());
msg.setProcessorId(testProc.getProcessorId());
msg.setSender(dlock.getDistributionManager().getId());
Thread thread = new Thread(() -> {
TXRecoverGrantorMessageProcessor proc = (TXRecoverGrantorMessageProcessor) dlock.getDLockRecoverGrantorMessageProcessor();
proc.processDLockRecoverGrantorMessage(dlock.getDistributionManager(), msg);
});
thread.setName("TXLockServiceDUnitTest thread");
thread.setDaemon(true);
thread.start();
await("waiting for recovery message to block").atMost(999, TimeUnit.MILLISECONDS).until(() -> {
return ((TXLockServiceImpl) dtls).isRecovering();
});
dtls.release(txLockId);
// check results to verify no locks were provided in the reply
await("waiting for thread to exit").atMost(30, TimeUnit.SECONDS).until(() -> {
return !thread.isAlive();
});
assertFalse(((TXLockServiceImpl) dtls).isRecovering());
assertEquals("testTXRecoverGrantor_replyCode_PASS is false", true, testTXRecoverGrantor_replyCode_PASS);
assertEquals("testTXRecoverGrantor_heldLocks_PASS is false", true, testTXRecoverGrantor_heldLocks_PASS);
}
use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.
the class TXLockServiceDUnitTest method testTXGrantorMigration.
@Test
public void testTXGrantorMigration() throws Exception {
// first make sure some other VM is the grantor
Host.getHost(0).getVM(0).invoke("become lock grantor", () -> {
TXLockService.createDTLS();
TXLockService vm0dtls = TXLockService.getDTLS();
DLockService vm0dlock = ((TXLockServiceImpl) vm0dtls).getInternalDistributedLockService();
vm0dlock.becomeLockGrantor();
});
TXLockService.createDTLS();
checkDLockRecoverGrantorMessageProcessor();
/*
* call TXRecoverGrantorMessageProcessor.process directly to make sure that correct behavior
* occurs
*/
// get txLock and hold it
final List regionLockReqs = new ArrayList();
regionLockReqs.add(new TXRegionLockRequestImpl("/testTXRecoverGrantorMessageProcessor2", new HashSet(Arrays.asList(new String[] { "KEY-1", "KEY-2", "KEY-3", "KEY-4" }))));
TXLockService dtls = TXLockService.getDTLS();
TXLockId txLockId = dtls.txLock(regionLockReqs, Collections.EMPTY_SET);
final DLockService dlock = ((TXLockServiceImpl) dtls).getInternalDistributedLockService();
// GEODE-2024: now cause grantor migration while holding the recoveryReadLock.
// It will lock up in TXRecoverGrantorMessageProcessor until the recoveryReadLock
// is released. Demonstrate that dtls.release() does not block forever and releases the
// recoveryReadLock
// allowing grantor migration to finish
// create an observer that will block recovery messages from being processed
MessageObserver observer = new MessageObserver();
DistributionMessageObserver.setInstance(observer);
try {
System.out.println("starting thread to take over being lock grantor from vm0");
// become the grantor - this will block waiting for a reply to the message blocked by the
// observer
Thread thread = new Thread(() -> {
dlock.becomeLockGrantor();
});
thread.setName("TXLockServiceDUnitTest thread2");
thread.setDaemon(true);
thread.start();
await("waiting for recovery to begin").atMost(10, TimeUnit.SECONDS).until(() -> {
return observer.isPreventingProcessing();
});
// spawn a thread that will unblock message processing
// so that TXLockServiceImpl's "recovering" variable will be set
System.out.println("starting a thread to unblock recovery in 5 seconds");
Thread unblockThread = new Thread(() -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException("sleep interrupted");
}
System.out.println("releasing block of recovery message processing");
observer.releasePreventionOfProcessing();
});
unblockThread.setName("TXLockServiceDUnitTest unblockThread");
unblockThread.setDaemon(true);
unblockThread.start();
// release txLock - this will block until unblockThread tells the observer
// that it can process its message. Then it should release the recovery read-lock
// allowing the grantor to finish recovery
System.out.println("releasing transaction locks, which should block for a bit");
dtls.release(txLockId);
await("waiting for recovery to finish").atMost(10, TimeUnit.SECONDS).until(() -> {
return !((TXLockServiceImpl) dtls).isRecovering();
});
} finally {
observer.releasePreventionOfProcessing();
DistributionMessageObserver.setInstance(null);
}
}
use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.
the class TXLockServiceDUnitTest method identifyLockGrantor.
private static InternalDistributedMember identifyLockGrantor(String serviceName) {
DLockService service = (DLockService) DistributedLockService.getServiceNamed(serviceName);
assertNotNull(service);
InternalDistributedMember grantor = service.getLockGrantorId().getLockGrantorMember();
assertNotNull(grantor);
logInfo("In identifyLockGrantor - grantor is " + grantor);
return grantor;
}
use of org.apache.geode.distributed.internal.locks.DLockService in project geode by apache.
the class TXLockServiceDUnitTest method isLockGrantor_DTLS.
/**
* Accessed via reflection. DO NOT REMOVE.
*/
protected static Boolean isLockGrantor_DTLS() {
TXLockService dtls = TXLockService.getDTLS();
if (true) {
DLockService service = DLockService.getInternalServiceNamed(((TXLockServiceImpl) dtls).getInternalDistributedLockService().getName());
assertNotNull(service);
assertEquals("DTLS and DLock should both report same isLockGrantor result", true, dtls.isLockGrantor() == service.isLockGrantor());
}
Boolean result = Boolean.valueOf(dtls.isLockGrantor());
logInfo("isLockGrantor_DTLS: " + result);
return result;
}
Aggregations