Search in sources :

Example 86 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition 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)

Example 87 with LogPosition

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

the class CorruptedLogsTruncator method truncateLogFiles.

private void truncateLogFiles(long recoveredTransactionLogVersion, long recoveredTransactionOffset, Optional<CheckpointInfo> corruptCheckpoint) throws IOException {
    LogFile transactionLogFile = logFiles.getLogFile();
    truncateFilesFromVersion(recoveredTransactionLogVersion, recoveredTransactionOffset, transactionLogFile.getHighestLogVersion(), transactionLogFile::getLogFileForVersion);
    if (corruptCheckpoint.isPresent()) {
        LogPosition checkpointPosition = corruptCheckpoint.get().getCheckpointEntryPosition();
        CheckpointFile checkpointFile = logFiles.getCheckpointFile();
        truncateFilesFromVersion(checkpointPosition.getLogVersion(), checkpointPosition.getByteOffset(), checkpointFile.getCurrentDetachedLogVersion(), checkpointFile::getDetachedCheckpointFileForVersion);
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 88 with LogPosition

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

the class CorruptedLogsTruncator method backupCorruptedContent.

private void backupCorruptedContent(long recoveredTransactionLogVersion, long recoveredTransactionOffset, Optional<CheckpointInfo> corruptCheckpoint) throws IOException {
    Path corruptedLogArchive = getArchiveFile(recoveredTransactionLogVersion, recoveredTransactionOffset);
    try (ZipOutputStream recoveryContent = new ZipOutputStream(fs.openAsOutputStream(corruptedLogArchive, false));
        var bufferScope = new HeapScopedBuffer(1, MebiByte, memoryTracker)) {
        LogFile transactionLogFile = logFiles.getLogFile();
        copyLogsContent(recoveredTransactionLogVersion, recoveredTransactionOffset, transactionLogFile.getHighestLogVersion(), recoveryContent, bufferScope, transactionLogFile::getLogFileForVersion);
        if (corruptCheckpoint.isPresent()) {
            LogPosition checkpointPosition = corruptCheckpoint.get().getCheckpointEntryPosition();
            CheckpointFile checkpointFile = logFiles.getCheckpointFile();
            copyLogsContent(checkpointPosition.getLogVersion(), checkpointPosition.getByteOffset(), checkpointFile.getCurrentDetachedLogVersion(), recoveryContent, bufferScope, checkpointFile::getDetachedCheckpointFileForVersion);
        }
    }
}
Also used : Path(java.nio.file.Path) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ZipOutputStream(java.util.zip.ZipOutputStream) CheckpointFile(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 89 with LogPosition

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

the class CorruptedLogsTruncator method findFirstCorruptDetachedCheckpoint.

private Optional<CheckpointInfo> findFirstCorruptDetachedCheckpoint(long recoveredTransactionLogVersion, long recoveredTransactionOffset) throws IOException {
    List<CheckpointInfo> detachedCheckpoints = logFiles.getCheckpointFile().getReachableDetachedCheckpoints();
    for (CheckpointInfo checkpoint : detachedCheckpoints) {
        LogPosition transactionLogPosition = checkpoint.getTransactionLogPosition();
        long logVersion = transactionLogPosition.getLogVersion();
        if (logVersion > recoveredTransactionLogVersion || (logVersion == recoveredTransactionLogVersion && transactionLogPosition.getByteOffset() > recoveredTransactionOffset)) {
            return Optional.of(checkpoint);
        }
    }
    return Optional.empty();
}
Also used : CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 90 with LogPosition

use of org.neo4j.kernel.impl.transaction.log.LogPosition 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)

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