Search in sources :

Example 16 with TransactionIdStore

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

the class TxPullRequestHandlerTest method shouldRespondWithEndOfStreamIfThereAreNoTransactions.

@Test
public void shouldRespondWithEndOfStreamIfThereAreNoTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(14L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(14, storeId));
    // then
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_STREAM, 14L));
}
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 17 with TransactionIdStore

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

the class TxPullRequestHandlerTest method shouldNotStreamTxEntriesIfStoreIdMismatches.

@Test
public void shouldNotStreamTxEntriesIfStoreIdMismatches() throws Exception {
    // given
    StoreId serverStoreId = new StoreId(1, 2, 3, 4);
    StoreId clientStoreId = new StoreId(5, 6, 7, 8);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> serverStoreId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(1, clientStoreId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_STORE_ID_MISMATCH, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", 2L, clientStoreId, serverStoreId));
}
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 18 with TransactionIdStore

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

the class TxPullRequestHandlerTest method shouldRespondWithoutTransactionsIfTheyDoNotExist.

@Test
public void shouldRespondWithoutTransactionsIfTheyDoNotExist() 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)).thenThrow(new NoSuchTransactionException(14));
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_TRANSACTION_PRUNED, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", 14L));
}
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) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 19 with TransactionIdStore

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

the class StoreUpgradeIntegrationTest method checkProvidedParameters.

private static void checkProvidedParameters(Store store, GraphDatabaseAPI db) {
    try (Transaction ignored = db.beginTx()) {
        // count nodes
        long nodeCount = count(db.getAllNodes());
        assertThat(nodeCount, is(store.expectedNodeCount));
        // count indexes
        long indexCount = count(db.schema().getIndexes());
        assertThat(indexCount, is(store.indexes()));
        // check last committed tx
        TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency(TransactionIdStore.class);
        long lastCommittedTxId = txIdStore.getLastCommittedTransactionId();
        try (Statement statement = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class).getKernelTransactionBoundToThisThread(true).acquireStatement()) {
            long countsTxId = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts().txId();
            assertEquals(lastCommittedTxId, countsTxId);
            assertThat(lastCommittedTxId, is(store.lastTxId));
        }
    }
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)

Example 20 with TransactionIdStore

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

the class BoltFactoryImplTest method txIdStoreRefreshedAfterRestart.

@Test
public void txIdStoreRefreshedAfterRestart() throws Throwable {
    GraphDatabaseAPI db = newDbMock();
    DependencyResolver dependencyResolver = db.getDependencyResolver();
    TransactionIdStore txIdStoreBeforeRestart = mock(TransactionIdStore.class);
    when(txIdStoreBeforeRestart.getLastClosedTransactionId()).thenReturn(42L);
    TransactionIdStore txIdStoreAfterRestart = mock(TransactionIdStore.class);
    when(txIdStoreAfterRestart.getLastClosedTransactionId()).thenReturn(4242L);
    when(dependencyResolver.resolveDependency(TransactionIdStore.class)).thenReturn(txIdStoreBeforeRestart).thenReturn(txIdStoreAfterRestart);
    BoltFactoryImpl boltFactory = newBoltFactory(db);
    boltFactory.start();
    BoltStateMachine stateMachine1 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
    assertEquals(42, stateMachine1.spi.transactionSpi().newestEncounteredTxId());
    boltFactory.stop();
    boltFactory.start();
    BoltStateMachine stateMachine2 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
    assertEquals(4242, stateMachine2.spi.transactionSpi().newestEncounteredTxId());
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

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