Search in sources :

Example 1 with NoSuchTransactionException

use of org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException 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 2 with NoSuchTransactionException

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

the class RemoteStore method getPullIndex.

/**
     * Later stages of the startup process require at least one transaction to
     * figure out the mapping between the transaction log and the consensus log.
     *
     * If there are no transaction logs then we can pull from and including
     * the index which the metadata store points to. This would be the case
     * for example with a backup taken during an idle period of the system.
     *
     * However, if there are transaction logs then we want to find out where
     * they end and pull from there, excluding the last one so that we do not
     * get duplicate entries.
     */
private long getPullIndex(File storeDir) throws IOException {
    /* this is the metadata store */
    ReadOnlyTransactionIdStore txIdStore = new ReadOnlyTransactionIdStore(pageCache, storeDir);
    /* Clean as in clean shutdown. Without transaction logs this should be the truth,
        * but otherwise it can be used as a starting point for scanning the logs. */
    long lastCleanTxId = txIdStore.getLastCommittedTransactionId();
    /* these are the transaction logs */
    ReadOnlyTransactionStore txStore = new ReadOnlyTransactionStore(pageCache, fs, storeDir, new Monitors());
    long lastTxId = BASE_TX_ID;
    try (Lifespan ignored = new Lifespan(txStore)) {
        TransactionCursor cursor;
        try {
            cursor = txStore.getTransactions(lastCleanTxId);
        } catch (NoSuchTransactionException e) {
            log.info("No transaction logs found. Will use metadata store as base for pull request.");
            return lastCleanTxId;
        }
        while (cursor.next()) {
            CommittedTransactionRepresentation tx = cursor.get();
            lastTxId = tx.getCommitEntry().getTxId();
        }
        if (lastTxId < lastCleanTxId) {
            throw new IllegalStateException("Metadata index was higher than transaction log index.");
        }
        // we don't want to pull a transaction we already have in the log, hence +1
        return lastTxId + 1;
    }
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) Monitors(org.neo4j.kernel.monitoring.Monitors) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) ReadOnlyTransactionStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore)

Example 3 with NoSuchTransactionException

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

the class TxPullRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, final TxPullRequest msg) throws Exception {
    long firstTxId = Math.max(msg.previousTxId(), BASE_TX_ID) + 1;
    long lastTxId = firstTxId;
    CatchupResult status = SUCCESS_END_OF_STREAM;
    StoreId localStoreId = storeIdSupplier.get();
    long lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
    if (localStoreId == null || !localStoreId.equals(msg.expectedStoreId())) {
        status = E_STORE_ID_MISMATCH;
        log.info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", lastTxId, msg.expectedStoreId(), localStoreId);
    } else if (!databaseAvailable.getAsBoolean()) {
        // database is not available for pulling transactions...
        status = E_STORE_UNAVAILABLE;
        log.info("Failed to serve TxPullRequest for tx %d because the local database is unavailable.", lastTxId);
    } else if (lastCommittedTransactionId >= firstTxId) {
        try (IOCursor<CommittedTransactionRepresentation> cursor = logicalTransactionStore.getTransactions(firstTxId)) {
            status = SUCCESS_END_OF_BATCH;
            for (int i = 0; i < batchSize; i++) {
                if (cursor.next()) {
                    ctx.write(ResponseMessageType.TX);
                    CommittedTransactionRepresentation tx = cursor.get();
                    lastTxId = tx.getCommitEntry().getTxId();
                    ctx.write(new TxPullResponse(localStoreId, tx));
                } else {
                    status = SUCCESS_END_OF_STREAM;
                    break;
                }
            }
            ctx.flush();
        } catch (NoSuchTransactionException e) {
            status = E_TRANSACTION_PRUNED;
            log.info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", lastTxId);
        }
    }
    ctx.write(ResponseMessageType.TX_STREAM_FINISHED);
    TxStreamFinishedResponse response = new TxStreamFinishedResponse(status, lastCommittedTransactionId);
    ctx.write(response);
    ctx.flush();
    monitor.increment();
    protocol.expect(State.MESSAGE_TYPE);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) StoreId(org.neo4j.causalclustering.identity.StoreId) CatchupResult(org.neo4j.causalclustering.catchup.CatchupResult) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException)

Example 4 with NoSuchTransactionException

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

the class HighlyAvailableEditionModule method assureLastCommitTimestampInitialized.

private static void assureLastCommitTimestampInitialized(DependencyResolver resolver) {
    MetaDataStore metaDataStore = resolver.resolveDependency(MetaDataStore.class);
    LogicalTransactionStore txStore = resolver.resolveDependency(LogicalTransactionStore.class);
    TransactionId txInfo = metaDataStore.getLastCommittedTransaction();
    long lastCommitTimestampFromStore = txInfo.commitTimestamp();
    if (txInfo.transactionId() == TransactionIdStore.BASE_TX_ID) {
        metaDataStore.setLastTransactionCommitTimestamp(TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP);
        return;
    }
    if (lastCommitTimestampFromStore == TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP || lastCommitTimestampFromStore == TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) {
        long lastCommitTimestampFromLogs;
        try {
            TransactionMetadata metadata = txStore.getMetadataFor(txInfo.transactionId());
            lastCommitTimestampFromLogs = metadata.getTimeWritten();
        } catch (NoSuchTransactionException e) {
            lastCommitTimestampFromLogs = TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP;
        } catch (IOException e) {
            throw new IllegalStateException("Unable to read transaction logs", e);
        }
        metaDataStore.setLastTransactionCommitTimestamp(lastCommitTimestampFromLogs);
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) IOException(java.io.IOException) TransactionId(org.neo4j.kernel.impl.store.TransactionId) TransactionMetadata(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)

Example 5 with NoSuchTransactionException

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

the class LogVersionLocatorTest method shouldNotFindLogPosition.

@Test
public void shouldNotFindLogPosition() throws NoSuchTransactionException {
    // given
    final long txId = 1L;
    final PhysicalLogicalTransactionStore.LogVersionLocator locator = new PhysicalLogicalTransactionStore.LogVersionLocator(txId);
    final LogPosition position = new LogPosition(1, 128);
    // when
    final boolean result = locator.visit(position, firstTxIdInLog, lastTxIdInLog);
    // then
    assertTrue(result);
    try {
        locator.getLogPosition();
        fail("should have thrown");
    } catch (NoSuchTransactionException e) {
        assertEquals("Unable to find transaction " + txId + " in any of my logical logs: " + "Couldn't find any log containing " + txId, e.getMessage());
    }
}
Also used : PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Aggregations

NoSuchTransactionException (org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException)5 Test (org.junit.Test)2 StoreId (org.neo4j.causalclustering.identity.StoreId)2 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)2 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)2 Monitors (org.neo4j.kernel.monitoring.Monitors)2 IOException (java.io.IOException)1 CatchupResult (org.neo4j.causalclustering.catchup.CatchupResult)1 CatchupServerProtocol (org.neo4j.causalclustering.catchup.CatchupServerProtocol)1 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)1 TransactionId (org.neo4j.kernel.impl.store.TransactionId)1 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)1 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)1 ReadOnlyTransactionIdStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore)1 ReadOnlyTransactionStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore)1 TransactionCursor (org.neo4j.kernel.impl.transaction.log.TransactionCursor)1 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)1 TransactionMetadata (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)1 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)1