Search in sources :

Example 1 with TransactionMetadata

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

the class PhysicalLogicalTransactionStore method getTransactions.

@Override
public TransactionCursor getTransactions(final long transactionIdToStartFrom) throws IOException {
    // look up in position cache
    try {
        TransactionMetadataCache.TransactionMetadata transactionMetadata = transactionMetadataCache.getTransactionMetadata(transactionIdToStartFrom);
        if (transactionMetadata != null) {
            // we're good
            ReadableLogChannel channel = logFile.getReader(transactionMetadata.getStartPosition());
            return new PhysicalTransactionCursor<>(channel, logEntryReader);
        }
        // ask LogFile about the version it may be in
        LogVersionLocator headerVisitor = new LogVersionLocator(transactionIdToStartFrom);
        logFile.accept(headerVisitor);
        // ask LogFile
        TransactionPositionLocator transactionPositionLocator = new TransactionPositionLocator(transactionIdToStartFrom, logEntryReader);
        logFile.accept(transactionPositionLocator, headerVisitor.getLogPosition());
        LogPosition position = transactionPositionLocator.getAndCacheFoundLogPosition(transactionMetadataCache);
        return new PhysicalTransactionCursor<>(logFile.getReader(position), logEntryReader);
    } catch (FileNotFoundException e) {
        throw new NoSuchTransactionException(transactionIdToStartFrom, "Log position acquired, but couldn't find the log file itself. Perhaps it just recently was deleted? [" + e.getMessage() + "]");
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) TransactionMetadata(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)

Example 2 with TransactionMetadata

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

the class PhysicalLogicalTransactionStore method getMetadataFor.

@Override
public TransactionMetadata getMetadataFor(long transactionId) throws IOException {
    if (transactionId <= BASE_TX_ID) {
        return METADATA_FOR_EMPTY_STORE;
    }
    TransactionMetadata transactionMetadata = transactionMetadataCache.getTransactionMetadata(transactionId);
    if (transactionMetadata == null) {
        try (IOCursor<CommittedTransactionRepresentation> cursor = getTransactions(transactionId)) {
            while (cursor.next()) {
                CommittedTransactionRepresentation tx = cursor.get();
                LogEntryCommit commitEntry = tx.getCommitEntry();
                long committedTxId = commitEntry.getTxId();
                long timeWritten = commitEntry.getTimeWritten();
                TransactionMetadata metadata = transactionMetadataCache.cacheTransactionMetadata(committedTxId, tx.getStartEntry().getStartPosition(), tx.getStartEntry().getMasterId(), tx.getStartEntry().getLocalId(), LogEntryStart.checksum(tx.getStartEntry()), timeWritten);
                if (committedTxId == transactionId) {
                    transactionMetadata = metadata;
                }
            }
        }
        if (transactionMetadata == null) {
            throw new NoSuchTransactionException(transactionId);
        }
    }
    return transactionMetadata;
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) TransactionMetadata(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)

Example 3 with TransactionMetadata

use of org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata 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 4 with TransactionMetadata

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

the class PhysicalLogicalTransactionStoreTest method verifyTransaction.

private void verifyTransaction(TransactionIdStore transactionIdStore, TransactionMetadataCache positionCache, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store) throws IOException {
    TransactionMetadata expectedMetadata;
    try (TransactionCursor cursor = store.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
        boolean hasNext = cursor.next();
        assertTrue(hasNext);
        CommittedTransactionRepresentation tx = cursor.get();
        TransactionRepresentation transaction = tx.getTransactionRepresentation();
        assertArrayEquals(additionalHeader, transaction.additionalHeader());
        assertEquals(masterId, transaction.getMasterId());
        assertEquals(authorId, transaction.getAuthorId());
        assertEquals(timeStarted, transaction.getTimeStarted());
        assertEquals(timeCommitted, transaction.getTimeCommitted());
        assertEquals(latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted());
        expectedMetadata = new TransactionMetadata(masterId, authorId, tx.getStartEntry().getStartPosition(), tx.getStartEntry().checksum(), timeCommitted);
    }
    positionCache.clear();
    TransactionMetadata actualMetadata = store.getMetadataFor(transactionIdStore.getLastCommittedTransactionId());
    assertEquals(expectedMetadata, actualMetadata);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionMetadata(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)

Aggregations

TransactionMetadata (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)4 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)1 TransactionId (org.neo4j.kernel.impl.store.TransactionId)1 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)1 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)1 NoSuchTransactionException (org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException)1 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)1