use of org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor in project neo4j by neo4j.
the class Database method buildTransactionMonitor.
private void buildTransactionMonitor(KernelTransactions kernelTransactions, Config config) {
KernelTransactionMonitor kernelTransactionTimeoutMonitor = new KernelTransactionMonitor(kernelTransactions, clock, databaseLogService);
databaseDependencies.satisfyDependency(kernelTransactionTimeoutMonitor);
TransactionMonitorScheduler transactionMonitorScheduler = new TransactionMonitorScheduler(kernelTransactionTimeoutMonitor, scheduler, config.get(GraphDatabaseSettings.transaction_monitor_check_interval).toMillis(), namedDatabaseId.name());
life.add(transactionMonitorScheduler);
}
use of org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor 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.impl.api.transaction.monitor.KernelTransactionMonitor in project neo4j by neo4j.
the class KernelTransactionTimeoutMonitorTest method terminateExpiredTransactions.
@Test
void terminateExpiredTransactions() {
Set<KernelTransactionHandle> transactions = new HashSet<>();
KernelTransactionImplementation tx1 = prepareTxMock(3, 1, 3);
KernelTransactionImplementation tx2 = prepareTxMock(4, 1, 8);
KernelTransactionImplementationHandle handle1 = new KernelTransactionImplementationHandle(tx1, fakeClock);
KernelTransactionImplementationHandle handle2 = new KernelTransactionImplementationHandle(tx2, fakeClock);
transactions.add(handle1);
transactions.add(handle2);
when(kernelTransactions.activeTransactions()).thenReturn(transactions);
KernelTransactionMonitor transactionMonitor = buildTransactionMonitor();
fakeClock.forward(3, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx1, never()).markForTermination(Status.Transaction.TransactionTimedOut);
verify(tx2, never()).markForTermination(Status.Transaction.TransactionTimedOut);
assertThat(logProvider).doesNotContainMessage("timeout");
fakeClock.forward(2, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx1).markForTermination(EXPECTED_REUSE_COUNT, Status.Transaction.TransactionTimedOut);
verify(tx2, never()).markForTermination(Status.Transaction.TransactionTimedOut);
assertThat(logProvider).containsMessages("timeout");
logProvider.clear();
fakeClock.forward(10, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx2).markForTermination(EXPECTED_REUSE_COUNT, Status.Transaction.TransactionTimedOut);
assertThat(logProvider).containsMessages("timeout");
}
use of org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor in project neo4j by neo4j.
the class KernelTransactionTimeoutMonitorTest method skipTransactionWithoutTimeout.
@Test
void skipTransactionWithoutTimeout() {
Set<KernelTransactionHandle> transactions = new HashSet<>();
KernelTransactionImplementation tx1 = prepareTxMock(7, 3, 0);
KernelTransactionImplementation tx2 = prepareTxMock(8, 4, 0);
KernelTransactionImplementationHandle handle1 = new KernelTransactionImplementationHandle(tx1, fakeClock);
KernelTransactionImplementationHandle handle2 = new KernelTransactionImplementationHandle(tx2, fakeClock);
transactions.add(handle1);
transactions.add(handle2);
when(kernelTransactions.activeTransactions()).thenReturn(transactions);
KernelTransactionMonitor transactionMonitor = buildTransactionMonitor();
fakeClock.forward(300, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx1, never()).markForTermination(Status.Transaction.TransactionTimedOut);
verify(tx2, never()).markForTermination(Status.Transaction.TransactionTimedOut);
assertThat(logProvider).doesNotContainMessage("timeout");
}
Aggregations