use of org.neo4j.lock.ActiveLock in project neo4j by neo4j.
the class TransactionDependenciesResolverTest method blockingChainDescriptionForChainedBlockedTransaction.
@Test
void blockingChainDescriptionForChainedBlockedTransaction() {
HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 4, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 4, 1)));
TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 5, singletonList(new ActiveLock(ResourceTypes.NODE, SHARED, 5, 2)));
TestKernelTransactionHandle handle3 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 6);
map.put(handle1, Optional.of(createQuerySnapshot(1)));
map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, EXCLUSIVE, ResourceTypes.NODE, 5, 1)));
map.put(handle3, Optional.of(createQuerySnapshotWaitingForLock(3, EXCLUSIVE, ResourceTypes.NODE, 6, 2)));
TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
assertEquals("[transaction-4]", resolver.describeBlockingTransactions(handle2));
assertEquals("[transaction-4, transaction-5]", resolver.describeBlockingTransactions(handle3));
}
use of org.neo4j.lock.ActiveLock in project neo4j by neo4j.
the class TransactionDependenciesResolverTest method detectBlockedTransactionsBySharedLock.
@Test
void detectBlockedTransactionsBySharedLock() {
HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 0, singletonList(new ActiveLock(ResourceTypes.NODE, SHARED, 1, 1)));
TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
map.put(handle1, Optional.of(createQuerySnapshot(1)));
map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, EXCLUSIVE, ResourceTypes.NODE, 1, 1)));
TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
assertFalse(resolver.isBlocked(handle1));
assertTrue(resolver.isBlocked(handle2));
}
use of org.neo4j.lock.ActiveLock in project neo4j by neo4j.
the class TransactionDependenciesResolver method evaluateDirectDependencies.
private static void evaluateDirectDependencies(Map<KernelTransactionHandle, Set<KernelTransactionHandle>> directDependencies, Map<KernelTransactionHandle, List<ActiveLock>> handleLocksMap, KernelTransactionHandle txHandle, QuerySnapshot querySnapshot) {
List<ActiveLock> waitingOnLocks = querySnapshot.waitingLocks();
for (ActiveLock activeLock : waitingOnLocks) {
for (Map.Entry<KernelTransactionHandle, List<ActiveLock>> handleListEntry : handleLocksMap.entrySet()) {
KernelTransactionHandle kernelTransactionHandle = handleListEntry.getKey();
if (!kernelTransactionHandle.equals(txHandle)) {
if (isBlocked(activeLock, handleListEntry.getValue())) {
Set<KernelTransactionHandle> kernelTransactionHandles = directDependencies.computeIfAbsent(txHandle, handle -> new HashSet<>());
kernelTransactionHandles.add(kernelTransactionHandle);
}
}
}
}
}
use of org.neo4j.lock.ActiveLock in project neo4j by neo4j.
the class ActiveLocksListingCompatibility method shouldListLocksHeldByTheCurrentClient.
@Test
void shouldListLocksHeldByTheCurrentClient() {
// given
clientA.initialize(LeaseService.NO_LEASES.newClient(), 1, EmptyMemoryTracker.INSTANCE, Config.defaults());
clientA.acquireExclusive(LockTracer.NONE, NODE, 1, 2, 3);
clientA.acquireShared(LockTracer.NONE, NODE, 3, 4, 5);
// when
Stream<ActiveLock> locks = clientA.activeLocks();
// then
assertEquals(new HashSet<>(asList(new ActiveLock(NODE, LockType.EXCLUSIVE, 1, 1), new ActiveLock(NODE, LockType.EXCLUSIVE, 1, 2), new ActiveLock(NODE, LockType.EXCLUSIVE, 1, 3), new ActiveLock(NODE, LockType.SHARED, 1, 3), new ActiveLock(NODE, LockType.SHARED, 1, 4), new ActiveLock(NODE, LockType.SHARED, 1, 5))), locks.collect(toSet()));
}
Aggregations