Search in sources :

Example 1 with KernelTransactionHandle

use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.

the class TransactionBatchCommitter method markUnsafeTransactionsForTermination.

private void markUnsafeTransactionsForTermination(TransactionToApply first, TransactionToApply last) {
    long firstCommittedTimestamp = first.transactionRepresentation().getTimeCommitted();
    long lastCommittedTimestamp = last.transactionRepresentation().getTimeCommitted();
    long earliestSafeTimestamp = lastCommittedTimestamp - idReuseSafeZoneTime;
    for (KernelTransactionHandle txHandle : kernelTransactions.activeTransactions()) {
        long commitTimestamp = txHandle.lastTransactionTimestampWhenStarted();
        if (commitTimestamp != TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP && commitTimestamp < earliestSafeTimestamp) {
            log.info("Marking transaction for termination, " + "invalidated due to an upcoming batch of changes being applied:" + "\n" + "  Batch: firstCommittedTxId:" + first.transactionId() + ", firstCommittedTimestamp:" + informativeTimestamp(firstCommittedTimestamp) + ", lastCommittedTxId:" + last.transactionId() + ", lastCommittedTimestamp:" + informativeTimestamp(lastCommittedTimestamp) + ", batchTimeRange:" + informativeDuration(lastCommittedTimestamp - firstCommittedTimestamp) + ", earliestSafeTimstamp:" + informativeTimestamp(earliestSafeTimestamp) + ", safeZoneDuration:" + informativeDuration(idReuseSafeZoneTime) + "\n" + "  Transaction: lastCommittedTimestamp:" + informativeTimestamp(txHandle.lastTransactionTimestampWhenStarted()) + ", lastCommittedTxId:" + txHandle.lastTransactionIdWhenStarted() + ", localStartTimestamp:" + informativeTimestamp(txHandle.startTime()));
            txHandle.markForTermination(Status.Transaction.Outdated);
        }
    }
}
Also used : KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle)

Example 2 with KernelTransactionHandle

use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.

the class KernelTransactionMonitorTest method shouldNotTimeoutSchemaTransactions.

@Test
void shouldNotTimeoutSchemaTransactions() {
    // given
    KernelTransactions kernelTransactions = mock(KernelTransactions.class);
    FakeClock clock = new FakeClock(100, MINUTES);
    KernelTransactionMonitor monitor = new KernelTransactionMonitor(kernelTransactions, clock, NullLogService.getInstance());
    // a 2 minutes old schema transaction which has a timeout of 1 minute
    KernelTransactionHandle oldSchemaTransaction = mock(KernelTransactionHandle.class);
    when(oldSchemaTransaction.isSchemaTransaction()).thenReturn(true);
    when(oldSchemaTransaction.startTime()).thenReturn(clock.millis() - MINUTES.toMillis(2));
    when(oldSchemaTransaction.timeoutMillis()).thenReturn(MINUTES.toMillis(1));
    when(kernelTransactions.activeTransactions()).thenReturn(Iterators.asSet(oldSchemaTransaction));
    // when
    monitor.run();
    // then
    verify(oldSchemaTransaction, times(1)).isSchemaTransaction();
    verify(oldSchemaTransaction, never()).markForTermination(any());
}
Also used : KernelTransactionMonitor(org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor) FakeClock(org.neo4j.time.FakeClock) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 3 with KernelTransactionHandle

use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method blockingChainDescriptionForDirectlyBlockedTransaction.

@Test
void blockingChainDescriptionForDirectlyBlockedTransaction() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 3, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 1, 1)));
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, SHARED, ResourceTypes.NODE, 1, 1)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
    assertEquals("[transaction-3]", resolver.describeBlockingTransactions(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 4 with KernelTransactionHandle

use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method detectBlockedTransactionsByExclusiveLock.

@Test
void detectBlockedTransactionsByExclusiveLock() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 0, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 1, 1)));
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, SHARED, 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 5 with KernelTransactionHandle

use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method blockingChainDescriptionForIndependentTransactionsIsEmpty.

@Test
void blockingChainDescriptionForIndependentTransactionsIsEmpty() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshot(2)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
    assertThat(resolver.describeBlockingTransactions(handle2)).isEmpty();
}
Also used : 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)

Aggregations

KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)20 HashMap (java.util.HashMap)11 Test (org.junit.jupiter.api.Test)9 Optional (java.util.Optional)8 TestKernelTransactionHandle (org.neo4j.kernel.impl.api.TestKernelTransactionHandle)6 ActiveLock (org.neo4j.lock.ActiveLock)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)4 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)4 Description (org.neo4j.procedure.Description)4 Procedure (org.neo4j.procedure.Procedure)4 ArrayList (java.util.ArrayList)3 AdminActionOnResource (org.neo4j.internal.kernel.api.security.AdminActionOnResource)3 DatabaseScope (org.neo4j.internal.kernel.api.security.AdminActionOnResource.DatabaseScope)3 UserSegment (org.neo4j.internal.kernel.api.security.UserSegment)3 KernelTransactionMonitor (org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor)3 ZoneId (java.time.ZoneId)2 List (java.util.List)2 Set (java.util.Set)2