Search in sources :

Example 1 with KernelTransactionMonitor

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);
}
Also used : KernelTransactionMonitor(org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor) TransactionMonitorScheduler(org.neo4j.kernel.impl.api.transaction.monitor.TransactionMonitorScheduler)

Example 2 with KernelTransactionMonitor

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

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");
}
Also used : KernelTransactionMonitor(org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with KernelTransactionMonitor

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");
}
Also used : KernelTransactionMonitor(org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

KernelTransactionMonitor (org.neo4j.kernel.impl.api.transaction.monitor.KernelTransactionMonitor)4 Test (org.junit.jupiter.api.Test)3 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)3 HashSet (java.util.HashSet)2 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1 TransactionMonitorScheduler (org.neo4j.kernel.impl.api.transaction.monitor.TransactionMonitorScheduler)1 FakeClock (org.neo4j.time.FakeClock)1