use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class DumpLogicalLog method dump.
public void dump(String filenameOrDirectory, PrintStream out, Predicate<LogEntry[]> filter, Function<LogEntry, String> serializer) throws IOException {
File file = new File(filenameOrDirectory);
printFile(file, out);
File firstFile;
LogVersionBridge bridge;
if (file.isDirectory()) {
// Use natural log version bridging if a directory is supplied
final PhysicalLogFiles logFiles = new PhysicalLogFiles(file, fileSystem);
bridge = new ReaderLogVersionBridge(fileSystem, logFiles) {
@Override
public LogVersionedStoreChannel next(LogVersionedStoreChannel channel) throws IOException {
LogVersionedStoreChannel next = super.next(channel);
if (next != channel) {
printFile(logFiles.getLogFileForVersion(next.getVersion()), out);
}
return next;
}
};
firstFile = logFiles.getLogFileForVersion(logFiles.getLowestLogVersion());
} else {
// Use no bridging, simple reading this single log file if a file is supplied
firstFile = file;
bridge = NO_MORE_CHANNELS;
}
StoreChannel fileChannel = fileSystem.open(firstFile, "r");
ByteBuffer buffer = ByteBuffer.allocateDirect(LOG_HEADER_SIZE);
LogHeader logHeader;
try {
logHeader = readLogHeader(buffer, fileChannel, false, firstFile);
} catch (IOException ex) {
out.println("Unable to read timestamp information, no records in logical log.");
out.println(ex.getMessage());
fileChannel.close();
throw ex;
}
out.println("Logical log format: " + logHeader.logFormatVersion + " version: " + logHeader.logVersion + " with prev committed tx[" + logHeader.lastCommittedTxId + "]");
PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
ReadableClosablePositionAwareChannel logChannel = new ReadAheadLogChannel(channel, bridge, DEFAULT_READ_AHEAD_SIZE);
LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
IOCursor<LogEntry> entryCursor = new LogEntryCursor(entryReader, logChannel);
TransactionLogEntryCursor transactionCursor = new TransactionLogEntryCursor(entryCursor);
try (IOCursor<LogEntry[]> cursor = filter == null ? transactionCursor : new FilteringIOCursor<>(transactionCursor, filter)) {
while (cursor.next()) {
for (LogEntry entry : cursor.get()) {
out.println(serializer.apply(entry));
}
}
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class RsdrMain method getLogCursor.
private static IOCursor<LogEntry> getLogCursor(FileSystemAbstraction fileSystem, String fname, NeoStores neoStores) throws IOException {
File file = new File(neoStores.getStoreDir(), fname);
StoreChannel fileChannel = fileSystem.open(file, "r");
LogHeader logHeader = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, false, file);
console.printf("Logical log version: %s with prev committed tx[%s]%n", logHeader.logVersion, logHeader.lastCommittedTxId);
PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
ReadableLogChannel logChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
return new LogEntryCursor(logEntryReader, logChannel);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class LogTestUtils method openLogEntryCursor.
private static LogEntryCursor openLogEntryCursor(FileSystemAbstraction fs, File firstFile, LogVersionBridge versionBridge) {
StoreChannel channel = null;
try {
channel = fs.open(firstFile, "r");
ByteBuffer buffer = ByteBuffer.allocate(LogHeader.LOG_HEADER_SIZE);
LogHeader header = LogHeaderReader.readLogHeader(buffer, channel, true, firstFile);
PhysicalLogVersionedStoreChannel logVersionedChannel = new PhysicalLogVersionedStoreChannel(channel, header.logVersion, header.logFormatVersion);
ReadableLogChannel logChannel = new ReadAheadLogChannel(logVersionedChannel, versionBridge, ReadAheadLogChannel.DEFAULT_READ_AHEAD_SIZE);
return new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel);
} catch (Throwable t) {
if (channel != null) {
try {
channel.close();
} catch (IOException e) {
t.addSuppressed(e);
}
}
throw new RuntimeException(t);
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class LogMatchers method logEntries.
public static List<LogEntry> logEntries(FileSystemAbstraction fileSystem, String logPath) throws IOException {
File logFile = new File(logPath);
StoreChannel fileChannel = fileSystem.open(logFile, "r");
// Always a header
LogHeader header = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, true, logFile);
// Read all log entries
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileChannel, header.logVersion, header.logFormatVersion);
ReadableLogChannel logChannel = new ReadAheadLogChannel(versionedStoreChannel, NO_MORE_CHANNELS);
LogEntryCursor logEntryCursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel);
return Iterables.asList(new IOCursorAsResourceIterable<>(logEntryCursor));
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class LegacyLogEntryReader method openReadableChannel.
public Pair<LogHeader, IOCursor<LogEntry>> openReadableChannel(File logFile) throws IOException {
final StoreChannel rawChannel = fs.open(logFile, "r");
final LogHeader header = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), rawChannel, false, logFile);
LogEntryReader<ReadableLogChannel> reader = readerFactory.apply(header);
// this ensures that the last committed txId field in the header is initialized properly
long lastCommittedTxId = Math.max(BASE_TX_ID, header.lastCommittedTxId);
final PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(rawChannel, header.logVersion, header.logFormatVersion);
final ReadableLogChannel readableChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
final IOCursor<LogEntry> cursor = new LogEntrySortingCursor(reader, readableChannel);
return Pair.of(new LogHeader(CURRENT_LOG_VERSION, header.logVersion, lastCommittedTxId), cursor);
}
Aggregations