Search in sources :

Example 36 with LogEntry

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

the class LogEntrySortingCursorTest method assertCursorContains.

private void assertCursorContains(Iterable<LogEntry> entries, LogEntrySortingCursor cursor) throws IOException {
    for (LogEntry entry : entries) {
        assertTrue(cursor.next());
        assertEquals(entry, cursor.get());
    }
    assertFalse(cursor.next());
}
Also used : IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 37 with LogEntry

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

the class LogEntrySortingCursorTest method shouldReorderWhenEntriesAreMixedUp.

@Test
public void shouldReorderWhenEntriesAreMixedUp() throws IOException {
    // given
    final LogEntry start1 = start(3);
    final LogEntry command1 = command();
    final LogEntry commit1 = commit(5);
    final LogEntry start2 = start(3);
    final LogEntry command2 = command();
    final LogEntry commit2 = commit(4);
    when(reader.readLogEntry(channel)).thenReturn(id(start2, 2), id(start1, 1), id(command1, 1), id(command2, 2), id(commit2, 2), id(commit1, 1), null);
    // when
    final LogEntrySortingCursor cursor = new LogEntrySortingCursor(reader, channel);
    // then
    final List<LogEntry> expected = Arrays.asList(start2, command2, commit2, start1, command1, commit1);
    assertCursorContains(expected, cursor);
}
Also used : IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Test(org.junit.Test)

Example 38 with LogEntry

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

the class TransactionLogFile method scanToEndOfLastLogEntry.

private LogPosition scanToEndOfLastLogEntry() throws IOException {
    // scroll all over possible checkpoints
    try (ReadAheadLogChannel readAheadLogChannel = new ReadAheadLogChannel(new UncloseableChannel(channel), memoryTracker)) {
        LogEntryReader logEntryReader = context.getLogEntryReader();
        LogEntry entry;
        do {
            // seek to the end the records.
            entry = logEntryReader.readLogEntry(readAheadLogChannel);
        } while (entry != null);
        return logEntryReader.lastPosition();
    }
}
Also used : LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 39 with LogEntry

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry 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 40 with LogEntry

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

Aggregations

LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)44 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)14 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)14 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)12 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)12 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)12 Test (org.junit.Test)10 File (java.io.File)9 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)9 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)8 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)7 IdentifiableLogEntry (org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry)7 ArrayList (java.util.ArrayList)6 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)5 StorageCommand (org.neo4j.storageengine.api.StorageCommand)5 IOException (java.io.IOException)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4