Search in sources :

Example 21 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class TransactionStateMachineSPITest method throwsWhenTxAwaitDurationExpires.

@Test
public void throwsWhenTxAwaitDurationExpires() throws Exception {
    long lastClosedTransactionId = 100;
    TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
    Duration txAwaitDuration = Duration.ofSeconds(42);
    FakeClock clock = new FakeClock();
    AvailabilityGuard availabilityGuard = spy(new AvailabilityGuard(clock, NullLog.getInstance()));
    when(availabilityGuard.isAvailable()).then(invocation -> {
        boolean available = (boolean) invocation.callRealMethod();
        clock.forward(txAwaitDuration.getSeconds() + 1, SECONDS);
        return available;
    });
    TransactionStateMachineSPI txSpi = createTxSpi(txIdStore, txAwaitDuration, availabilityGuard, clock);
    Future<Void> result = otherThread.execute(state -> {
        txSpi.awaitUpToDate(lastClosedTransactionId + 42);
        return null;
    });
    try {
        result.get(20, SECONDS);
    } catch (Exception e) {
        assertThat(e, instanceOf(ExecutionException.class));
        assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
    }
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) FakeClock(org.neo4j.time.FakeClock) Duration(java.time.Duration) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) ExecutionException(java.util.concurrent.ExecutionException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Test(org.junit.Test)

Example 22 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class TransactionStateMachineSPITest method fixedTxIdStore.

private static TransactionIdStore fixedTxIdStore(long lastClosedTransactionId) {
    TransactionIdStore txIdStore = mock(TransactionIdStore.class);
    when(txIdStore.getLastClosedTransactionId()).thenReturn(lastClosedTransactionId);
    return txIdStore;
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore)

Example 23 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class TxPullRequestHandlerTest method shouldNotStreamTxsAndReportErrorIfTheLocalDatabaseIsNotAvailable.

@Test
public void shouldNotStreamTxsAndReportErrorIfTheLocalDatabaseIsNotAvailable() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> false, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(1, storeId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_STORE_UNAVAILABLE, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the local database is unavailable.", 2L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 24 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class TxPullRequestHandlerTest method shouldRespondWithBatchOfTransactions.

@Test
public void shouldRespondWithBatchOfTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    when(logicalTransactionStore.getTransactions(14L)).thenReturn(txCursor(cursor(tx(14), tx(15), tx(16), tx(17))));
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
    // then
    verify(context, times(3)).write(ResponseMessageType.TX);
    verify(context).write(new TxPullResponse(storeId, tx(14)));
    verify(context).write(new TxPullResponse(storeId, tx(15)));
    verify(context).write(new TxPullResponse(storeId, tx(16)));
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_BATCH, 15L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 25 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class ReadReplicaReplicationIT method transactionIdTracker.

private TransactionIdTracker transactionIdTracker(GraphDatabaseAPI database) {
    TransactionIdStore transactionIdStore = database.getDependencyResolver().resolveDependency(TransactionIdStore.class);
    AvailabilityGuard availabilityGuard = database.getDependencyResolver().resolveDependency(AvailabilityGuard.class);
    return new TransactionIdTracker(transactionIdStore, availabilityGuard, Clock.systemUTC());
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) TransactionIdTracker(org.neo4j.kernel.api.txtracking.TransactionIdTracker)

Aggregations

TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)33 Test (org.junit.Test)23 Monitors (org.neo4j.kernel.monitoring.Monitors)11 StoreId (org.neo4j.kernel.impl.store.StoreId)9 TransactionId (org.neo4j.kernel.impl.store.TransactionId)9 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)9 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)8 IOException (java.io.IOException)7 URI (java.net.URI)7 BranchedDataPolicy (org.neo4j.kernel.ha.BranchedDataPolicy)7 CatchupServerProtocol (org.neo4j.causalclustering.catchup.CatchupServerProtocol)6 StoreId (org.neo4j.causalclustering.identity.StoreId)6 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)6 File (java.io.File)5 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)5 DependencyResolver (org.neo4j.graphdb.DependencyResolver)4 CancellationRequest (org.neo4j.helpers.CancellationRequest)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 PageCache (org.neo4j.io.pagecache.PageCache)4 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)4