Search in sources :

Example 1 with LogEntryDetachedCheckpoint

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

the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs.

@Test
void shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs() throws Exception {
    // GIVEN
    long txLogLowVersion = 2;
    long txLogHighVersion = 10;
    long checkpointLogLowVersion = 0;
    long checkpointLogHighVersion = 3;
    StoreId storeId = new StoreId(12345);
    LogPosition checkpointLogPosition = new LogPosition(checkpointLogHighVersion, 34);
    Database database = databaseWithLogFilesContainingLowestTxId(logs(transactionLogsWithTransaction(txLogLowVersion, txLogHighVersion, 42), checkpointLogsWithLastCheckpoint(checkpointLogLowVersion, checkpointLogHighVersion, new CheckpointInfo(new LogEntryDetachedCheckpoint(KernelVersion.LATEST, checkpointLogPosition, 1234, storeId, "testing"), checkpointLogPosition))));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log logger = logProvider.getLog(getClass());
    // WHEN
    new TransactionRangeDiagnostics(database).dump(logger::info);
    // THEN
    assertThat(logProvider).containsMessages("existing transaction log versions " + txLogLowVersion + "-" + txLogHighVersion).containsMessages("existing checkpoint log versions " + checkpointLogLowVersion + "-" + checkpointLogHighVersion);
}
Also used : LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) StoreId(org.neo4j.storageengine.api.StoreId) Log(org.neo4j.logging.Log) Database(org.neo4j.kernel.database.Database) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 2 with LogEntryDetachedCheckpoint

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

the class CheckpointLogFile method reachableCheckpoints.

@Override
public List<CheckpointInfo> reachableCheckpoints() throws IOException {
    var versionVisitor = new RangeLogVersionVisitor();
    fileHelper.accept(versionVisitor);
    long highestVersion = versionVisitor.getHighestVersion();
    if (highestVersion < 0) {
        return emptyList();
    }
    long currentVersion = versionVisitor.getLowestVersion();
    var checkpointReader = new VersionAwareLogEntryReader(NO_COMMANDS, true);
    var checkpoints = new ArrayList<CheckpointInfo>();
    while (currentVersion <= highestVersion) {
        try (var channel = channelAllocator.openLogChannel(currentVersion);
            var reader = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS, context.getMemoryTracker());
            var logEntryCursor = new LogEntryCursor(checkpointReader, reader)) {
            log.info("Scanning log file with version %d for checkpoint entries", currentVersion);
            LogEntryDetachedCheckpoint checkpoint;
            var lastCheckpointLocation = reader.getCurrentPosition();
            var lastLocation = lastCheckpointLocation;
            while (logEntryCursor.next()) {
                lastCheckpointLocation = lastLocation;
                LogEntry logEntry = logEntryCursor.get();
                checkpoint = verify(logEntry);
                checkpoints.add(new CheckpointInfo(checkpoint, lastCheckpointLocation));
                lastLocation = reader.getCurrentPosition();
            }
            currentVersion++;
        }
    }
    return checkpoints;
}
Also used : LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) RangeLogVersionVisitor(org.neo4j.kernel.impl.transaction.log.files.RangeLogVersionVisitor) ArrayList(java.util.ArrayList) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 3 with LogEntryDetachedCheckpoint

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

the class CheckpointLogFile method findLatestCheckpoint.

@Override
public Optional<CheckpointInfo> findLatestCheckpoint() throws IOException {
    var versionVisitor = new RangeLogVersionVisitor();
    fileHelper.accept(versionVisitor);
    long highestVersion = versionVisitor.getHighestVersion();
    if (highestVersion < 0) {
        return Optional.empty();
    }
    long lowestVersion = versionVisitor.getLowestVersion();
    long currentVersion = highestVersion;
    var checkpointReader = new VersionAwareLogEntryReader(NO_COMMANDS, true);
    while (currentVersion >= lowestVersion) {
        try (var channel = channelAllocator.openLogChannel(currentVersion);
            var reader = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS, context.getMemoryTracker());
            var logEntryCursor = new LogEntryCursor(checkpointReader, reader)) {
            log.info("Scanning log file with version %d for checkpoint entries", currentVersion);
            LogEntryDetachedCheckpoint checkpoint = null;
            var lastCheckpointLocation = reader.getCurrentPosition();
            var lastLocation = lastCheckpointLocation;
            while (logEntryCursor.next()) {
                lastCheckpointLocation = lastLocation;
                LogEntry logEntry = logEntryCursor.get();
                checkpoint = verify(logEntry);
                lastLocation = reader.getCurrentPosition();
            }
            if (checkpoint != null) {
                return Optional.of(new CheckpointInfo(checkpoint, lastCheckpointLocation));
            }
            currentVersion--;
        }
    }
    return Optional.empty();
}
Also used : LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) RangeLogVersionVisitor(org.neo4j.kernel.impl.transaction.log.files.RangeLogVersionVisitor) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 4 with LogEntryDetachedCheckpoint

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

the class CheckpointInfoTest method checkpointInfoOfDetachedCheckpointEntry.

@Test
void checkpointInfoOfDetachedCheckpointEntry() {
    var logPosition = new LogPosition(0, 1);
    var storeId = new StoreId(3, 4, 5, 6, 7);
    LogPosition position = new LogPosition(1, 2);
    var checkpointInfo = new CheckpointInfo(new LogEntryDetachedCheckpoint(KernelVersion.V4_0, logPosition, 2, storeId, "checkpoint"), position);
    assertSame(logPosition, checkpointInfo.getTransactionLogPosition());
    assertSame(storeId, checkpointInfo.storeId());
    assertSame(position, checkpointInfo.getCheckpointEntryPosition());
}
Also used : LogEntryDetachedCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint) StoreId(org.neo4j.storageengine.api.StoreId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Aggregations

LogEntryDetachedCheckpoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint)4 Test (org.junit.jupiter.api.Test)2 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)2 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 RangeLogVersionVisitor (org.neo4j.kernel.impl.transaction.log.files.RangeLogVersionVisitor)2 StoreId (org.neo4j.storageengine.api.StoreId)2 ArrayList (java.util.ArrayList)1 Database (org.neo4j.kernel.database.Database)1 CheckpointInfo (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 Log (org.neo4j.logging.Log)1