Search in sources :

Example 11 with ReadableLogChannel

use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel in project neo4j by neo4j.

the class LogTestUtils method filterNeostoreLogicalLog.

public static File filterNeostoreLogicalLog(FileSystemAbstraction fileSystem, File file, final LogHook<LogEntry> filter) throws IOException {
    filter.file(file);
    File tempFile = new File(file.getAbsolutePath() + ".tmp");
    fileSystem.deleteFile(tempFile);
    try (StoreChannel in = fileSystem.open(file, "r");
        StoreChannel out = fileSystem.open(tempFile, "rw")) {
        LogHeader logHeader = transferLogicalLogHeader(in, out, ByteBuffer.allocate(LOG_HEADER_SIZE));
        PhysicalLogVersionedStoreChannel outChannel = new PhysicalLogVersionedStoreChannel(out, logHeader.logVersion, logHeader.logFormatVersion);
        PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(in, logHeader.logVersion, logHeader.logFormatVersion);
        ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel, LogVersionBridge.NO_MORE_CHANNELS);
        LogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>();
        LogEntry entry;
        while ((entry = entryReader.readLogEntry(inBuffer)) != null) {
            if (filter.test(entry)) {
            // TODO allright, write to outBuffer
            }
        }
    }
    return tempFile;
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 12 with ReadableLogChannel

use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel in project neo4j by neo4j.

the class LegacyLogEntryReaderTest method shouldReadTheEntries.

@Test
public void shouldReadTheEntries() throws IOException {
    // given
    final LogEntry start = new LogEntryStart(0, 1, 2, 3, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    NodeRecord record = new NodeRecord(42);
    final LogEntry command = new LogEntryCommand(new Command.NodeCommand(record, record));
    final LogEntry commit = new OnePhaseCommit(42, 43);
    final LogEntryReader<ReadableLogChannel> logEntryReader = mock(LogEntryReader.class);
    when(logEntryReader.readLogEntry(any(ReadableLogChannel.class))).thenReturn(new IdentifiableLogEntry(start, 1), new IdentifiableLogEntry(command, 1), new IdentifiableLogEntry(commit, 1), null);
    final LegacyLogEntryReader reader = new LegacyLogEntryReader(fs, from -> logEntryReader);
    // when
    final IOCursor<LogEntry> cursor = reader.openReadableChannel(input).other();
    // then
    assertTrue(cursor.next());
    assertEquals(start, cursor.get());
    assertTrue(cursor.next());
    assertEquals(command, cursor.get());
    assertTrue(cursor.next());
    assertEquals(commit, cursor.get());
    assertFalse(cursor.next());
    cursor.close();
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) Test(org.junit.Test)

Aggregations

ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)12 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)8 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)7 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)6 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)6 StoreChannel (org.neo4j.io.fs.StoreChannel)5 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)5 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)5 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)5 File (java.io.File)4 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)4 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)4 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)3 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)3 IOException (java.io.IOException)2 TimeUnit (java.util.concurrent.TimeUnit)2 LogVersionRepository (org.neo4j.kernel.impl.transaction.log.LogVersionRepository)2 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)2 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)2 SimpleTriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo)2