Search in sources :

Example 6 with LogEntry

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);
}
Also used : IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Test(org.junit.Test)

Example 7 with LogEntry

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);
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CountingLogHook(org.neo4j.test.LogTestUtils.CountingLogHook) LogFileInformation(org.neo4j.kernel.impl.transaction.log.LogFileInformation) IOException(java.io.IOException) File(java.io.File) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 8 with LogEntry

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));
            }
        }
    }
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) LogVersionBridge(org.neo4j.kernel.impl.transaction.log.LogVersionBridge) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) TransactionLogEntryCursor(org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor) TransactionLogEntryCursor(org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 9 with LogEntry

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);
        }
    }
}
Also used : TimeZone(java.util.TimeZone) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 10 with LogEntry

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");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) RecordStore(org.neo4j.kernel.impl.store.RecordStore) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Aggregations

LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)44 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)14 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)14 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)12 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)12 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)12 Test (org.junit.Test)10 File (java.io.File)9 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)9 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)8 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)7 IdentifiableLogEntry (org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry)7 ArrayList (java.util.ArrayList)6 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)5 StorageCommand (org.neo4j.storageengine.api.StorageCommand)5 IOException (java.io.IOException)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4