Search in sources :

Example 56 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class FileSenderTest method sendSmallFile.

@Test
public void sendSmallFile() throws Exception {
    // given
    byte[] bytes = new byte[10];
    random.nextBytes(bytes);
    File smallFile = testDirectory.file("smallFile");
    try (StoreChannel storeChannel = fs.create(smallFile)) {
        storeChannel.write(ByteBuffer.wrap(bytes));
    }
    FileSender fileSender = new FileSender(fs.open(smallFile, "r"));
    // when + then
    assertFalse(fileSender.isEndOfInput());
    assertEquals(FileChunk.create(bytes, true), fileSender.readChunk(allocator));
    assertNull(fileSender.readChunk(allocator));
    assertTrue(fileSender.isEndOfInput());
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) Test(org.junit.Test)

Example 57 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class CheckTxLogsTest method writeContent.

private void writeContent(File log, ThrowingConsumer<TransactionLogWriter, IOException> consumer) throws IOException {
    FileSystemAbstraction fs = ensureLogExists(log);
    try (StoreChannel channel = fs.open(log, "rw");
        LogVersionedStoreChannel versionedChannel = new PhysicalLogVersionedStoreChannel(channel, 0, (byte) 0);
        PhysicalFlushableChannel writableLogChannel = new PhysicalFlushableChannel(versionedChannel)) {
        long offset = channel.size();
        channel.position(offset);
        consumer.accept(new TransactionLogWriter(new LogEntryWriter(writableLogChannel)));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)

Example 58 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class RecoveryProtocolTest method createLogFile.

private void createLogFile(EphemeralFileSystemAbstraction fsa, long prevFileLastIndex, long fileNameVersion, long headerVersion, long prevIndex, long prevTerm) throws IOException {
    StoreChannel channel = fsa.open(fileNames.getForVersion(fileNameVersion), "w");
    PhysicalFlushableChannel writer = new PhysicalFlushableChannel(channel);
    headerMarshal.marshal(new SegmentHeader(prevFileLastIndex, headerVersion, prevIndex, prevTerm), writer);
    writer.prepareForFlush().flush();
    channel.close();
}
Also used : PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel)

Example 59 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class SegmentFileTest method shouldNotReturnReaderExperiencingErrorToPool.

@Test
public void shouldNotReturnReaderExperiencingErrorToPool() throws Exception {
    // given
    StoreChannel channel = mock(StoreChannel.class);
    Reader reader = mock(Reader.class);
    ReaderPool readerPool = mock(ReaderPool.class);
    when(channel.read(any(ByteBuffer.class))).thenThrow(new IOException());
    when(reader.channel()).thenReturn(channel);
    when(readerPool.acquire(anyLong(), anyLong())).thenReturn(reader);
    try (SegmentFile segment = create(fsRule.get(), fileNames.getForVersion(0), readerPool, 0, contentMarshal, logProvider, segmentHeader)) {
        // given
        IOCursor<EntryRecord> cursor = segment.getCursor(0);
        try {
            cursor.next();
            fail();
        } catch (IOException e) {
        // expected from mocking
        }
        // when
        cursor.close();
        // then
        verify(readerPool, never()).release(reader);
        verify(reader).close();
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) IOException(java.io.IOException) EntryRecord(org.neo4j.causalclustering.core.consensus.log.EntryRecord) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 60 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingFirstPage.

@Test
public void mustFlushDirtyPagesOnEvictingFirstPage() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
    ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
    MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
    PagedFile pagedFile = pageCache.map(file("a"), 8);
    try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
        assertTrue(cursor.next());
        cursor.putLong(0L);
    }
    cursorTracer.reportEvents();
    assertNotNull(cursorTracer.observe(Fault.class));
    assertEquals(1, cursorTracer.faults());
    assertEquals(1, tracer.faults());
    int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
    assertThat(clockArm, is(1));
    assertNotNull(tracer.observe(Evict.class));
    ByteBuffer buf = ByteBuffer.allocate(16);
    StoreChannel channel = fs.open(file("a"), "r");
    channel.read(buf);
    buf.flip();
    assertThat(buf.getLong(), is(0L));
    assertThat(buf.getLong(), is(y));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Aggregations

StoreChannel (org.neo4j.io.fs.StoreChannel)113 Test (org.junit.Test)71 File (java.io.File)65 ByteBuffer (java.nio.ByteBuffer)48 IOException (java.io.IOException)20 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)17 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)15 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)13 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)11 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)10 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)7 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)7 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)7 InputStream (java.io.InputStream)6 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)6 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)6 HashSet (java.util.HashSet)5 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)5 PageSwapper (org.neo4j.io.pagecache.PageSwapper)5 PagedFile (org.neo4j.io.pagecache.PagedFile)5