Search in sources :

Example 6 with CheckpointInfo

use of org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo 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 7 with CheckpointInfo

use of org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo 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 8 with CheckpointInfo

use of org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo 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

CheckpointInfo (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo)8 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)5 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)2 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 StoreChannel (org.neo4j.io.fs.StoreChannel)2 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)2 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)2 UncheckedIOException (java.io.UncheckedIOException)1 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)1 Database (org.neo4j.kernel.database.Database)1 LogEntryDetachedCheckpoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 Log (org.neo4j.logging.Log)1 StoreId (org.neo4j.storageengine.api.StoreId)1