use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LogEntrySortingCursorTest method shouldReorderBasedOnTheTxId.
@Test
public void shouldReorderBasedOnTheTxId() 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(start1, 1), id(command1, 1), id(start2, 2), 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);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class ReadTransactionLogWritingTest method countLogEntries.
private long countLogEntries() {
GraphDatabaseAPI db = dbr.getGraphDatabaseAPI();
FileSystemAbstraction fs = db.getDependencyResolver().resolveDependency(FileSystemAbstraction.class);
File storeDir = new File(db.getStoreDir());
try {
CountingLogHook<LogEntry> logicalLogCounter = new CountingLogHook<>();
filterNeostoreLogicalLog(fs, storeDir.getPath(), logicalLogCounter);
long txLogRecordCount = db.getDependencyResolver().resolveDependency(LogFileInformation.class).getLastEntryId();
return logicalLogCounter.getCount() + txLogRecordCount;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry 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.entry.LogEntry in project neo4j by neo4j.
the class RsdrMain method readLog.
private static void readLog(IOCursor<LogEntry> cursor, final long fromLine, final long toLine, final Pattern pattern) throws IOException {
TimeZone timeZone = TimeZone.getDefault();
long lineCount = -1;
while (cursor.next()) {
LogEntry logEntry = cursor.get();
lineCount++;
if (lineCount > toLine) {
return;
}
if (lineCount < fromLine) {
continue;
}
String str = logEntry.toString(timeZone);
if (pattern == null || pattern.matcher(str).find()) {
console.printf("%s%n", str);
}
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class RsdrMain method read.
private static void read(FileSystemAbstraction fileSystem, String cmd, NeoStores neoStores) throws IOException {
Matcher matcher = readCommandPattern.matcher(cmd);
if (matcher.find()) {
String lower = matcher.group("lower");
String upper = matcher.group("upper");
String fname = matcher.group("fname");
String regex = matcher.group("regex");
Pattern pattern = regex != null ? Pattern.compile(regex) : null;
long fromId = lower != null ? Long.parseLong(lower) : 0L;
long toId = upper != null ? Long.parseLong(upper) : Long.MAX_VALUE;
RecordStore store = getStore(fname, neoStores);
if (store != null) {
readStore(fileSystem, store, fromId, toId, pattern);
return;
}
IOCursor<LogEntry> cursor = getLogCursor(fileSystem, fname, neoStores);
if (cursor != null) {
readLog(cursor, fromId, toId, pattern);
cursor.close();
return;
}
console.printf("don't know how to read '%s'%n", fname);
} else {
console.printf("bad read command format%n");
}
}
Aggregations