Search in sources :

Example 6 with ActiveLock

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));
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 7 with ActiveLock

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));
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 8 with ActiveLock

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);
                }
            }
        }
    }
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle)

Example 9 with ActiveLock

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()));
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) Test(org.junit.jupiter.api.Test)

Aggregations

ActiveLock (org.neo4j.lock.ActiveLock)9 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)5 Optional (java.util.Optional)4 TestKernelTransactionHandle (org.neo4j.kernel.impl.api.TestKernelTransactionHandle)4 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 MutableLongBag (org.eclipse.collections.api.bag.primitive.MutableLongBag)1 LongIntMap (org.eclipse.collections.api.map.primitive.LongIntMap)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)1 ResourceType (org.neo4j.lock.ResourceType)1 MapValue (org.neo4j.values.virtual.MapValue)1