use of org.neo4j.kernel.impl.transaction.log.files.RangeLogVersionVisitor 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;
}
use of org.neo4j.kernel.impl.transaction.log.files.RangeLogVersionVisitor 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();
}
Aggregations