Search in sources :

Example 21 with LogTailInformation

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

the class RecoveryStartInformationProviderTest method shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero.

@Test
void shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero() {
    // given
    long oldestLogVersionFound = 1L;
    when(logFile.getLowestLogVersion()).thenReturn(oldestLogVersionFound);
    when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(true, 10L, false, currentLogVersion, LATEST.version()));
    // when
    UnderlyingStorageException storageException = assertThrows(UnderlyingStorageException.class, () -> new RecoveryStartInformationProvider(logFiles, monitor).get());
    final String expectedMessage = "No check point found in any log file from version " + oldestLogVersionFound + " to " + logVersion;
    assertEquals(expectedMessage, storageException.getMessage());
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) Test(org.junit.jupiter.api.Test)

Example 22 with LogTailInformation

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

the class RecoveryStartInformationProviderTest method shouldReturnUnspecifiedIfThereIsNoNeedForRecovery.

@Test
void shouldReturnUnspecifiedIfThereIsNoNeedForRecovery() {
    // given
    when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(false, NO_TRANSACTION_ID, false, currentLogVersion, LATEST.version()));
    // when
    RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider(logFiles, monitor).get();
    // then
    verify(monitor).noCommitsAfterLastCheckPoint(null);
    assertEquals(LogPosition.UNSPECIFIED, recoveryStartInformation.getTransactionLogPosition());
    assertEquals(LogPosition.UNSPECIFIED, recoveryStartInformation.getCheckpointPosition());
    assertEquals(NO_TRANSACTION_ID, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint());
    assertFalse(recoveryStartInformation.isRecoveryRequired());
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) Test(org.junit.jupiter.api.Test)

Example 23 with LogTailInformation

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

the class RecoveryStartInformationProviderTest method shouldReturnLogPositionToRecoverFromIfNeeded.

@Test
void shouldReturnLogPositionToRecoverFromIfNeeded() {
    // given
    LogPosition txPosition = new LogPosition(1L, 4242);
    LogPosition checkpointPosition = new LogPosition(2, 4);
    when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(new CheckpointInfo(txPosition, StoreId.UNKNOWN, checkpointPosition), true, 10L, false, currentLogVersion, LATEST.version(), StoreId.UNKNOWN));
    // when
    RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider(logFiles, monitor).get();
    // then
    verify(monitor).commitsAfterLastCheckPoint(txPosition, 10L);
    assertEquals(txPosition, recoveryStartInformation.getTransactionLogPosition());
    assertEquals(checkpointPosition, recoveryStartInformation.getCheckpointPosition());
    assertEquals(10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint());
    assertTrue(recoveryStartInformation.isRecoveryRequired());
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 24 with LogTailInformation

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

the class InlinedLogTailScanner method findLogTail.

protected LogTailInformation findLogTail() throws IOException {
    LogFile logFile = logFiles.getLogFile();
    final long highestLogVersion = logFile.getHighestLogVersion();
    long version = highestLogVersion;
    long versionToSearchForCommits = highestLogVersion;
    LogEntryStart latestStartEntry = null;
    long oldestStartEntryTransaction = NO_TRANSACTION_ID;
    long oldestVersionFound = -1;
    byte latestLogEntryVersion = 0;
    boolean startRecordAfterCheckpoint = false;
    boolean corruptedTransactionLogs = false;
    while (version >= logFile.getLowestLogVersion() && version >= INITIAL_LOG_VERSION) {
        log.info("Scanning log file with version %d for checkpoint entries", version);
        oldestVersionFound = version;
        CheckpointInfo latestCheckPoint = null;
        StoreId storeId = StoreId.UNKNOWN;
        try (LogVersionedStoreChannel channel = logFile.openForVersion(version);
            var readAheadChannel = new ReadAheadLogChannel(channel, memoryTracker);
            LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadChannel)) {
            LogHeader logHeader = logFile.extractHeader(version);
            storeId = logHeader.getStoreId();
            LogEntry entry;
            long position = logHeader.getStartPosition().getByteOffset();
            long channelVersion = version;
            while (cursor.next()) {
                entry = cursor.get();
                // Collect data about latest checkpoint
                if (entry instanceof LogEntryInlinedCheckPoint) {
                    latestCheckPoint = new CheckpointInfo((LogEntryInlinedCheckPoint) entry, storeId, new LogPosition(channelVersion, position));
                } else if (entry instanceof LogEntryCommit) {
                    if (oldestStartEntryTransaction == NO_TRANSACTION_ID) {
                        oldestStartEntryTransaction = ((LogEntryCommit) entry).getTxId();
                    }
                } else if (entry instanceof LogEntryStart) {
                    LogEntryStart startEntry = (LogEntryStart) entry;
                    if (version == versionToSearchForCommits) {
                        latestStartEntry = startEntry;
                    }
                    startRecordAfterCheckpoint = true;
                }
                // Collect data about latest entry version, only in first log file
                if (version == versionToSearchForCommits || latestLogEntryVersion == 0) {
                    latestLogEntryVersion = entry.getVersion().version();
                }
                position = channel.position();
                channelVersion = channel.getVersion();
            }
            verifyReaderPosition(version, logEntryReader.lastPosition());
        } catch (Error | ClosedByInterruptException e) {
            // These should not be parsing errors
            throw e;
        } catch (Throwable t) {
            monitor.corruptedLogFile(version, t);
            if (failOnCorruptedLogFiles) {
                throwUnableToCleanRecover(t);
            }
            corruptedTransactionLogs = true;
        }
        if (latestCheckPoint != null) {
            return checkpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs, storeId);
        }
        version--;
        // if we have found no commits in the latest log, keep searching in the next one
        if (latestStartEntry == null) {
            versionToSearchForCommits--;
        }
    }
    return new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound == UNKNOWN, highestLogVersion, latestLogEntryVersion);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) StoreId(org.neo4j.storageengine.api.StoreId) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 25 with LogTailInformation

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

the class AbstractLogTailScannerTest method latestLogFileContainingACheckPointOnly.

@ParameterizedTest
@MethodSource("params")
void latestLogFileContainingACheckPointOnly(int startLogVersion, int endLogVersion) {
    // given
    setupLogFiles(endLogVersion, logFile(checkPoint()));
    // 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)

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