Search in sources :

Example 11 with PhysicalLogVersionedStoreChannel

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel 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 PhysicalLogVersionedStoreChannel

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

the class ReaderLogVersionBridgeTest method shouldOpenTheNextChannelWhenItExists.

@Test
public void shouldOpenTheNextChannelWhenItExists() throws IOException {
    // given
    final StoreChannel newStoreChannel = mock(StoreChannel.class);
    final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(fs, logFiles);
    when(channel.getVersion()).thenReturn(version);
    when(channel.getLogFormatVersion()).thenReturn(CURRENT_LOG_VERSION);
    when(logFiles.getLogFileForVersion(version + 1)).thenReturn(file);
    when(fs.fileExists(file)).thenReturn(true);
    when(fs.open(file, "r")).thenReturn(newStoreChannel);
    when(newStoreChannel.read(Matchers.<ByteBuffer>any())).then(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
            ByteBuffer buffer = (ByteBuffer) invocationOnMock.getArguments()[0];
            buffer.putLong(encodeLogVersion(version + 1));
            buffer.putLong(42);
            return LOG_HEADER_SIZE;
        }
    });
    // when
    final LogVersionedStoreChannel result = bridge.next(channel);
    // then
    PhysicalLogVersionedStoreChannel expected = new PhysicalLogVersionedStoreChannel(newStoreChannel, version + 1, CURRENT_LOG_VERSION);
    assertEquals(expected, result);
    verify(channel, times(1)).close();
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)12 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)7 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)7 File (java.io.File)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)5 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)5 Test (org.junit.Test)4 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)4 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)4 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)4 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)4 LogHeaderWriter.writeLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader)3 LogVersionBridge (org.neo4j.kernel.impl.transaction.log.LogVersionBridge)2 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1