use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader 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.LogHeader in project neo4j by neo4j.
the class TransactionLogChannelAllocatorIT method rawChannelDoesNotTryToAdviseOnFileContent.
@Test
void rawChannelDoesNotTryToAdviseOnFileContent() throws IOException {
Path path = fileHelper.getLogFileForVersion(1);
try (var storeChannel = fileSystem.write(path)) {
writeLogHeader(storeChannel, new LogHeader(CURRENT_LOG_FORMAT_VERSION, 1, 1, 1), INSTANCE);
}
var logHeaderCache = new LogHeaderCache(10);
var logFileContext = createLogFileContext();
var nativeChannelAccessor = new AdviseCountingChannelNativeAccessor();
var channelAllocator = new TransactionLogChannelAllocator(logFileContext, fileHelper, logHeaderCache, nativeChannelAccessor);
try (var channel = channelAllocator.openLogChannel(1, true)) {
assertEquals(0, nativeChannelAccessor.getCallCounter());
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class TransactionLogChannelAllocatorIT method defaultChannelTryToAdviseOnFileContent.
@Test
void defaultChannelTryToAdviseOnFileContent() throws IOException {
Path path = fileHelper.getLogFileForVersion(1);
try (StoreChannel storeChannel = fileSystem.write(path)) {
writeLogHeader(storeChannel, new LogHeader(CURRENT_LOG_FORMAT_VERSION, 1, 1, 1), INSTANCE);
}
var logHeaderCache = new LogHeaderCache(10);
var logFileContext = createLogFileContext();
var nativeChannelAccessor = new AdviseCountingChannelNativeAccessor();
var channelAllocator = new TransactionLogChannelAllocator(logFileContext, fileHelper, logHeaderCache, nativeChannelAccessor);
try (var channel = channelAllocator.openLogChannel(1)) {
assertEquals(1, nativeChannelAccessor.getCallCounter());
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LogTestUtils method filterTransactionLogFile.
private static void filterTransactionLogFile(FileSystemAbstraction fileSystem, Path file, final LogHook<LogEntry> filter, ChannelNativeAccessor channelNativeAccessor) throws IOException {
filter.file(file);
try (StoreChannel in = fileSystem.read(file)) {
LogHeader logHeader = readLogHeader(ByteBuffers.allocate(CURRENT_FORMAT_LOG_HEADER_SIZE, INSTANCE), in, true, file);
assert logHeader != null : "Looks like we tried to read a log header of an empty pre-allocated file.";
PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(in, logHeader.getLogVersion(), logHeader.getLogFormatVersion(), file, channelNativeAccessor);
ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel, INSTANCE);
LogEntryReader entryReader = new VersionAwareLogEntryReader(new TestCommandReaderFactory());
LogEntry entry;
while ((entry = entryReader.readLogEntry(inBuffer)) != null) {
filter.test(entry);
}
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LegacyLogs method getTransactionInformation.
public Optional<TransactionId> getTransactionInformation(File storeDir, long transactionId) throws IOException {
List<File> logFiles = Arrays.asList(fs.listFiles(storeDir, versionedLegacyLogFilesFilter));
logFiles.sort(NEWEST_FIRST);
for (File file : logFiles) {
Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(file);
boolean hadAnyTransactions = false;
try (IOCursor<LogEntry> cursor = pair.other()) {
// The log entries will come sorted from this cursor, so no need to keep track of identifiers and such.
LogEntryStart startEntry = null;
while (cursor.next()) {
LogEntry logEntry = cursor.get();
if (logEntry instanceof LogEntryStart) {
startEntry = (LogEntryStart) logEntry;
} else if (logEntry instanceof LogEntryCommit) {
hadAnyTransactions = true;
LogEntryCommit commitEntry = logEntry.as();
if (commitEntry.getTxId() == transactionId) {
return Optional.of(new TransactionId(transactionId, startEntry.checksum(), commitEntry.getTimeWritten()));
}
}
}
}
if (hadAnyTransactions) {
// No need to go further back than this. We're looking for the last transaction
break;
}
}
return Optional.empty();
}
Aggregations