Search in sources :

Example 96 with LogPosition

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

the class CorruptedLogsTruncatorTest method doNotPruneEmptyLogs.

@Test
void doNotPruneEmptyLogs() throws IOException {
    logPruner.truncate(new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE));
    assertTrue(FileSystemUtils.isEmptyOrNonExistingDirectory(fs, databaseDirectory));
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 97 with LogPosition

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

the class RecoveryProgressIndicatorTest method reportProgressOnRecovery.

@Test
void reportProgressOnRecovery() throws Throwable {
    RecoveryService recoveryService = mock(RecoveryService.class, Answers.RETURNS_MOCKS);
    CorruptedLogsTruncator logsTruncator = mock(CorruptedLogsTruncator.class);
    RecoveryMonitor recoveryMonitor = mock(RecoveryMonitor.class);
    TransactionCursor reverseTransactionCursor = mock(TransactionCursor.class);
    TransactionCursor transactionCursor = mock(TransactionCursor.class);
    CommittedTransactionRepresentation transactionRepresentation = mock(CommittedTransactionRepresentation.class);
    int transactionsToRecover = 5;
    int expectedMax = transactionsToRecover * 2;
    int lastCommittedTransactionId = 14;
    LogPosition transactionLogPosition = new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE);
    LogPosition checkpointLogPosition = new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE);
    int firstTxIdAfterLastCheckPoint = 10;
    RecoveryStartInformation startInformation = new RecoveryStartInformation(transactionLogPosition, checkpointLogPosition, firstTxIdAfterLastCheckPoint);
    when(reverseTransactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
    when(transactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
    when(reverseTransactionCursor.get()).thenReturn(transactionRepresentation);
    when(transactionCursor.get()).thenReturn(transactionRepresentation);
    when(transactionRepresentation.getCommitEntry()).thenReturn(new LogEntryCommit(lastCommittedTransactionId, 1L, BASE_TX_CHECKSUM));
    when(recoveryService.getRecoveryStartInformation()).thenReturn(startInformation);
    when(recoveryService.getTransactionsInReverseOrder(transactionLogPosition)).thenReturn(reverseTransactionCursor);
    when(recoveryService.getTransactions(transactionLogPosition)).thenReturn(transactionCursor);
    AssertableProgressReporter progressReporter = new AssertableProgressReporter(expectedMax);
    TransactionLogsRecovery recovery = new TransactionLogsRecovery(recoveryService, logsTruncator, new LifecycleAdapter(), recoveryMonitor, progressReporter, true, EMPTY_CHECKER, PageCacheTracer.NULL);
    recovery.init();
    progressReporter.verify();
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 98 with LogPosition

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

the class TransactionLogFile method accept.

@Override
public void accept(LogHeaderVisitor visitor) throws IOException {
    // Start from the where we're currently at and go backwards in time (versions)
    long logVersion = getHighestLogVersion();
    long highTransactionId = context.getLastCommittedTransactionId();
    while (versionExists(logVersion)) {
        LogHeader logHeader = extractHeader(logVersion, false);
        if (logHeader != null) {
            long lowTransactionId = logHeader.getLastCommittedTxId() + 1;
            LogPosition position = logHeader.getStartPosition();
            if (!visitor.visit(logHeader, position, lowTransactionId, highTransactionId)) {
                break;
            }
            highTransactionId = logHeader.getLastCommittedTxId();
        }
        logVersion--;
    }
}
Also used : LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 99 with LogPosition

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

the class LogFilesBuilder method closePositionSupplier.

private Supplier<LogPosition> closePositionSupplier() throws IOException {
    if (lastClosedPositionSupplier != null) {
        return lastClosedPositionSupplier;
    }
    if (transactionIdStore != null) {
        return () -> {
            long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
            return new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
        };
    }
    if (fileBasedOperationsOnly) {
        return () -> {
            throw new UnsupportedOperationException("Current version of log files can't perform any " + "operation that require availability of transaction id store. Please build full version of log files " + "to be able to use them.");
        };
    }
    if (readOnly) {
        requireNonNull(pageCache, "Read only log files require page cache to be able to read committed " + "transaction info from store store.");
        requireNonNull(databaseLayout, "Store directory is required.");
        TransactionIdStore transactionIdStore = readOnlyTransactionIdStore();
        return () -> {
            long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
            return new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
        };
    } else {
        requireNonNull(dependencies, TransactionIdStore.class.getSimpleName() + " is required. " + "Please provide an instance or a dependencies where it can be found.");
        return () -> {
            long[] lastClosedTransaction = resolveDependency(TransactionIdStore.class).getLastClosedTransaction();
            return new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
        };
    }
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 100 with LogPosition

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

the class DetachedLogTailScanner method getFirstTransactionIdAfterCheckpoint.

private StartCommitEntries getFirstTransactionIdAfterCheckpoint(LogFile logFile, LogPosition logPosition) throws IOException {
    boolean corruptedTransactionLogs = false;
    LogEntryStart start = null;
    LogEntryCommit commit = null;
    LogPosition lookupPosition = null;
    long logVersion = logPosition.getLogVersion();
    try {
        while (logFile.versionExists(logVersion)) {
            lookupPosition = lookupPosition == null ? logPosition : logFile.extractHeader(logVersion).getStartPosition();
            try (var reader = logFile.getReader(lookupPosition, NO_MORE_CHANNELS);
                var cursor = new LogEntryCursor(logEntryReader, reader)) {
                LogEntry entry;
                while ((start == null || commit == null) && cursor.next()) {
                    entry = cursor.get();
                    if (commit == null && entry instanceof LogEntryCommit) {
                        commit = (LogEntryCommit) entry;
                    } else if (start == null && entry instanceof LogEntryStart) {
                        start = (LogEntryStart) entry;
                    }
                }
            }
            if ((start != null) && (commit != null)) {
                return new StartCommitEntries(start, commit);
            }
            verifyReaderPosition(logVersion, logEntryReader.lastPosition());
            logVersion++;
        }
    } catch (Error | ClosedByInterruptException e) {
        // These should not be parsing errors
        throw e;
    } catch (Throwable t) {
        monitor.corruptedLogFile(logVersion, t);
        if (failOnCorruptedLogFiles) {
            throwUnableToCleanRecover(t);
        }
        corruptedTransactionLogs = true;
    }
    return new StartCommitEntries(start, commit, corruptedTransactionLogs);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Aggregations

LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)115 Test (org.junit.jupiter.api.Test)50 File (java.io.File)16 Test (org.junit.Test)16 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)15 Path (java.nio.file.Path)14 IOException (java.io.IOException)11 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)10 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)10 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)10 StoreId (org.neo4j.storageengine.api.StoreId)10 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)9 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)8 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)8 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)7 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)7