use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint in project neo4j by neo4j.
the class PhysicalTransactionCursor method next.
@Override
public boolean next() throws IOException {
// Clear the previous deserialized transaction so that it won't have to be kept in heap while deserializing
// the next one. Could be problematic if both are really big.
current = null;
while (true) {
if (!logEntryCursor.next()) {
return false;
}
LogEntry entry = logEntryCursor.get();
if (entry instanceof LogEntryInlinedCheckPoint) {
// this is a good position anyhow
channel.getCurrentPosition(lastGoodPositionMarker);
continue;
}
assert entry instanceof LogEntryStart : "Expected Start entry, read " + entry + " instead";
LogEntryStart startEntry = (LogEntryStart) entry;
LogEntryCommit commitEntry;
List<StorageCommand> entries = new ArrayList<>();
while (true) {
if (!logEntryCursor.next()) {
return false;
}
entry = logEntryCursor.get();
if (entry instanceof LogEntryCommit) {
commitEntry = (LogEntryCommit) entry;
break;
}
LogEntryCommand command = (LogEntryCommand) entry;
entries.add(command.getCommand());
}
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(entries);
transaction.setHeader(startEntry.getAdditionalHeader(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), commitEntry.getTimeWritten(), -1, ANONYMOUS);
current = new CommittedTransactionRepresentation(startEntry, transaction, commitEntry);
channel.getCurrentPosition(lastGoodPositionMarker);
return true;
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint in project neo4j by neo4j.
the class LegacyCheckpointLogFile method reachableCheckpoints.
public List<CheckpointInfo> reachableCheckpoints() throws IOException {
var logFile = logFiles.getLogFile();
long highestVersion = logFile.getHighestLogVersion();
if (highestVersion < 0) {
return emptyList();
}
long lowestVersion = logFile.getLowestLogVersion();
long currentVersion = highestVersion;
var checkpoints = new ArrayList<CheckpointInfo>();
while (currentVersion >= lowestVersion) {
try (var channel = logFile.openForVersion(currentVersion);
var reader = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS, context.getMemoryTracker());
var logEntryCursor = new LogEntryCursor(context.getLogEntryReader(), reader)) {
LogHeader logHeader = logFile.extractHeader(currentVersion);
var storeId = logHeader.getStoreId();
LogPosition lastLocation = reader.getCurrentPosition();
while (logEntryCursor.next()) {
LogEntry logEntry = logEntryCursor.get();
// Collect data about latest checkpoint
if (logEntry instanceof LogEntryInlinedCheckPoint) {
checkpoints.add(new CheckpointInfo((LogEntryInlinedCheckPoint) logEntry, storeId, lastLocation));
}
lastLocation = reader.getCurrentPosition();
}
currentVersion--;
}
}
return checkpoints;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint in project neo4j by neo4j.
the class CheckpointInfoTest method checkpointInfoOfLegacyCheckpointEntry.
@Test
void checkpointInfoOfLegacyCheckpointEntry() {
var logPosition = new LogPosition(0, 1);
StoreId storeId = new StoreId(1, 2, 3, 4, 5);
LogPosition position = new LogPosition(1, 2);
var checkpointInfo = new CheckpointInfo(new LogEntryInlinedCheckPoint(logPosition), storeId, position);
assertSame(logPosition, checkpointInfo.getTransactionLogPosition());
assertSame(storeId, checkpointInfo.storeId());
assertSame(position, checkpointInfo.getCheckpointEntryPosition());
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint in project neo4j by neo4j.
the class InlinedLogTailScanner method findLogTail.
protected LogTailInformation findLogTail() throws IOException {
LogFile logFile = logFiles.getLogFile();
final long highestLogVersion = logFile.getHighestLogVersion();
long version = highestLogVersion;
long versionToSearchForCommits = highestLogVersion;
LogEntryStart latestStartEntry = null;
long oldestStartEntryTransaction = NO_TRANSACTION_ID;
long oldestVersionFound = -1;
byte latestLogEntryVersion = 0;
boolean startRecordAfterCheckpoint = false;
boolean corruptedTransactionLogs = false;
while (version >= logFile.getLowestLogVersion() && version >= INITIAL_LOG_VERSION) {
log.info("Scanning log file with version %d for checkpoint entries", version);
oldestVersionFound = version;
CheckpointInfo latestCheckPoint = null;
StoreId storeId = StoreId.UNKNOWN;
try (LogVersionedStoreChannel channel = logFile.openForVersion(version);
var readAheadChannel = new ReadAheadLogChannel(channel, memoryTracker);
LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadChannel)) {
LogHeader logHeader = logFile.extractHeader(version);
storeId = logHeader.getStoreId();
LogEntry entry;
long position = logHeader.getStartPosition().getByteOffset();
long channelVersion = version;
while (cursor.next()) {
entry = cursor.get();
// Collect data about latest checkpoint
if (entry instanceof LogEntryInlinedCheckPoint) {
latestCheckPoint = new CheckpointInfo((LogEntryInlinedCheckPoint) entry, storeId, new LogPosition(channelVersion, position));
} else if (entry instanceof LogEntryCommit) {
if (oldestStartEntryTransaction == NO_TRANSACTION_ID) {
oldestStartEntryTransaction = ((LogEntryCommit) entry).getTxId();
}
} else if (entry instanceof LogEntryStart) {
LogEntryStart startEntry = (LogEntryStart) entry;
if (version == versionToSearchForCommits) {
latestStartEntry = startEntry;
}
startRecordAfterCheckpoint = true;
}
// Collect data about latest entry version, only in first log file
if (version == versionToSearchForCommits || latestLogEntryVersion == 0) {
latestLogEntryVersion = entry.getVersion().version();
}
position = channel.position();
channelVersion = channel.getVersion();
}
verifyReaderPosition(version, logEntryReader.lastPosition());
} catch (Error | ClosedByInterruptException e) {
// These should not be parsing errors
throw e;
} catch (Throwable t) {
monitor.corruptedLogFile(version, t);
if (failOnCorruptedLogFiles) {
throwUnableToCleanRecover(t);
}
corruptedTransactionLogs = true;
}
if (latestCheckPoint != null) {
return checkpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs, storeId);
}
version--;
// if we have found no commits in the latest log, keep searching in the next one
if (latestStartEntry == null) {
versionToSearchForCommits--;
}
}
return new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound == UNKNOWN, highestLogVersion, latestLogEntryVersion);
}
Aggregations