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);
}
}
}
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());
}
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));
}
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));
}
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();
}
Aggregations