Search in sources :

Example 16 with LogTailInformation

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

the class AbstractLogTailScannerTest method olderLogFileContainingACheckPointAndNewerFileIsEmpty.

@ParameterizedTest
@MethodSource("params")
void olderLogFileContainingACheckPointAndNewerFileIsEmpty(int startLogVersion, int endLogVersion) {
    // given
    StartEntry start = start();
    setupLogFiles(endLogVersion, logFile(start, commit(1), checkPoint()), logFile());
    // when
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    // then
    assertLatestCheckPoint(true, 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 17 with LogTailInformation

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

the class AbstractLogTailScannerTest method twoLogFilesNoCheckPointsOneStart.

@ParameterizedTest
@MethodSource("params")
void twoLogFilesNoCheckPointsOneStart(int startLogVersion, int endLogVersion) {
    // given
    long txId = 21;
    setupLogFiles(endLogVersion, logFile(), logFile(start(), commit(txId)));
    // when
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    // then
    assertLatestCheckPoint(false, 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)

Example 18 with LogTailInformation

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

the class RecoveryStartInformationProviderTest method detectMissingTransactionLogsInformation.

@Test
void detectMissingTransactionLogsInformation() {
    when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(false, -1, true, -1, LATEST.version()));
    RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider(logFiles, monitor).get();
    assertSame(MISSING_LOGS, recoveryStartInformation);
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) Test(org.junit.jupiter.api.Test)

Example 19 with LogTailInformation

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

the class RecoveryStartInformationProviderTest method shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero.

@Test
void shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero() {
    // given
    when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(true, 10L, false, currentLogVersion, LATEST.version()));
    // when
    RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider(logFiles, monitor).get();
    // then
    verify(monitor).noCheckPointFound();
    assertEquals(new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE), recoveryStartInformation.getTransactionLogPosition());
    assertEquals(new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE), recoveryStartInformation.getCheckpointPosition());
    assertEquals(10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint());
    assertTrue(recoveryStartInformation.isRecoveryRequired());
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 20 with LogTailInformation

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

the class RecoveryStartInformationProvider method get.

/**
 * Find the log position to start recovery from
 *
 * @return {@link LogPosition#UNSPECIFIED} if there is no need to recover otherwise the {@link LogPosition} to
 * start recovery from
 * @throws IOException if log files cannot be read
 */
@Override
public RecoveryStartInformation get() {
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    CheckpointInfo lastCheckPoint = logTailInformation.lastCheckPoint;
    long txIdAfterLastCheckPoint = logTailInformation.firstTxIdAfterLastCheckPoint;
    if (!logTailInformation.isRecoveryRequired()) {
        monitor.noCommitsAfterLastCheckPoint(lastCheckPoint != null ? lastCheckPoint.getTransactionLogPosition() : null);
        return NO_RECOVERY_REQUIRED;
    }
    if (logTailInformation.logsMissing()) {
        return MISSING_LOGS;
    }
    if (logTailInformation.commitsAfterLastCheckpoint()) {
        if (lastCheckPoint == null) {
            long lowestLogVersion = logFiles.getLogFile().getLowestLogVersion();
            if (lowestLogVersion != INITIAL_LOG_VERSION) {
                throw new UnderlyingStorageException("No check point found in any log file from version " + lowestLogVersion + " to " + logTailInformation.currentLogVersion);
            }
            monitor.noCheckPointFound();
            LogPosition position = tryExtractHeaderSize();
            return createRecoveryInformation(position, new LogPosition(INITIAL_LOG_VERSION, CURRENT_FORMAT_LOG_HEADER_SIZE), txIdAfterLastCheckPoint);
        }
        LogPosition transactionLogPosition = lastCheckPoint.getTransactionLogPosition();
        monitor.commitsAfterLastCheckPoint(transactionLogPosition, txIdAfterLastCheckPoint);
        return createRecoveryInformation(transactionLogPosition, lastCheckPoint.getCheckpointEntryPosition(), txIdAfterLastCheckPoint);
    } else {
        throw new UnderlyingStorageException("Fail to determine recovery information Log tail info: " + logTailInformation);
    }
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

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