Search in sources :

Example 1 with LogTailInformation

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

the class StoreUpgraderTest method removeCheckPointFromTxLog.

public static void removeCheckPointFromTxLog(FileSystemAbstraction fileSystem, Path databaseDirectory) throws IOException {
    LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, fileSystem).withCommandReaderFactory(RecordStorageCommandReaderFactory.INSTANCE).build();
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    if (logTailInformation.commitsAfterLastCheckpoint()) {
        // done already
        return;
    }
    // let's assume there is at least a checkpoint
    assertNotNull(logTailInformation.lastCheckPoint);
    LogPosition logPosition = logTailInformation.lastCheckPoint.getTransactionLogPosition();
    Path logFile = logFiles.getLogFile().getLogFileForVersion(logPosition.getLogVersion());
    long byteOffset = logPosition.getByteOffset();
    fileSystem.truncate(logFile, byteOffset);
}
Also used : Path(java.nio.file.Path) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 2 with LogTailInformation

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

the class LogsUpgrader method assertCleanlyShutDown.

public void assertCleanlyShutDown(DatabaseLayout layout) {
    Throwable suppressibleException = null;
    try {
        // we should not use provided database layout here since transaction log location is different compare to previous versions
        // and that's why we need to use custom transaction logs locator and database layout
        DatabaseLayout oldDatabaseLayout = buildLegacyLogsLayout(layout);
        LogFiles logFiles = buildLogFiles(oldDatabaseLayout);
        LogTailInformation tail = logFiles.getTailInformation();
        if (!tail.isRecoveryRequired()) {
            // All good
            return;
        }
        if (tail.logsMissing()) {
            // There are no log files in the legacy logs location.
            // Either log files are missing entirely, or they are already in their correct place.
            logFiles = buildLogFiles(layout);
            tail = logFiles.getTailInformation();
            if (!tail.isRecoveryRequired()) {
                // Log file is already in its new location, and looks good.
                return;
            }
            if (tail.logsMissing() && !config.get(fail_on_missing_files)) {
                // We don't have any log files, but we were told to ignore this.
                return;
            }
        }
    } catch (Throwable throwable) {
        // ignore exception and throw db not cleanly shutdown
        suppressibleException = throwable;
    }
    StoreUpgrader.DatabaseNotCleanlyShutDownException exception = new StoreUpgrader.DatabaseNotCleanlyShutDownException();
    if (suppressibleException != null) {
        exception.addSuppressed(suppressibleException);
    }
    throw exception;
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles)

Example 3 with LogTailInformation

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

the class AbstractLogTailScannerTest method twoLogFilesSecondIsCorruptedBeforeCommit.

@ParameterizedTest
@MethodSource("params")
void twoLogFilesSecondIsCorruptedBeforeCommit(int startLogVersion, int endLogVersion) throws IOException {
    setupLogFiles(endLogVersion, logFile(checkPoint()), logFile(start(), commit(2)));
    Path highestLogFile = logFiles.getLogFile().getHighestLogFile();
    fs.truncate(highestLogFile, fs.getFileSize(highestLogFile) - 3);
    // when
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    // then
    assertLatestCheckPoint(true, true, NO_TRANSACTION_ID, false, logTailInformation);
}
Also used : Path(java.nio.file.Path) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with LogTailInformation

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

the class AbstractLogTailScannerTest method twoLogFilesNoCheckPoints.

@ParameterizedTest
@MethodSource("params")
void twoLogFilesNoCheckPoints(int startLogVersion, int endLogVersion) {
    // given
    setupLogFiles(endLogVersion, logFile(), logFile());
    // when
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    // then
    assertLatestCheckPoint(false, false, NO_TRANSACTION_ID, false, logTailInformation);
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with LogTailInformation

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

the class AbstractLogTailScannerTest method latestLogFileContainingMultipleCheckPointsOneStartAfterBoth.

@ParameterizedTest
@MethodSource("params")
void latestLogFileContainingMultipleCheckPointsOneStartAfterBoth(int startLogVersion, int endLogVersion) {
    // given
    long txId = 11;
    setupLogFiles(endLogVersion, logFile(checkPoint(), checkPoint(), start(), commit(txId)));
    // when
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    // then
    assertLatestCheckPoint(true, true, txId, false, logTailInformation);
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)23 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)7 Test (org.junit.jupiter.api.Test)6 Path (java.nio.file.Path)3 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)2 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 CheckpointInfo (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo)2 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)1 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)1 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)1 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)1 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)1 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)1 LogEntryInlinedCheckPoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint)1 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)1 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)1