Search in sources :

Example 1 with ByteArrayPageCursor

use of org.neo4j.io.pagecache.ByteArrayPageCursor in project neo4j by neo4j.

the class SimpleEntryStorage method reader.

CURSOR reader() throws IOException {
    if (!allocated) {
        return reader(new ByteArrayPageCursor(NO_ENTRIES));
    }
    // Reuse the existing buffer because we're not writing while reading anyway
    ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<>(fs.read(file), byteBufferFactory.allocate(blockSize, memoryTracker));
    PageCursor pageCursor = new ReadableChannelPageCursor(channel);
    return reader(pageCursor);
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) PageCursor(org.neo4j.io.pagecache.PageCursor) ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor)

Example 2 with ByteArrayPageCursor

use of org.neo4j.io.pagecache.ByteArrayPageCursor in project neo4j by neo4j.

the class AdversarialReadPageCursorTest method shouldNotMessUpUnrelatedSegmentOnReadBytes.

@Test
void shouldNotMessUpUnrelatedSegmentOnReadBytes() throws Exception {
    // Given
    byte[] buf = new byte[4];
    byte[] page = new byte[] { 7 };
    AdversarialReadPageCursor cursor = new AdversarialReadPageCursor(new ByteArrayPageCursor(page), new PageCacheRule.AtomicBooleanInconsistentReadAdversary(new AtomicBoolean(true)));
    // When
    cursor.next(0);
    cursor.getBytes(buf, buf.length - 1, 1);
    cursor.shouldRetry();
    cursor.getBytes(buf, buf.length - 1, 1);
    // Then the range outside of buf.length-1, buf.length should be pristine
    assertEquals(0, buf[0]);
    assertEquals(0, buf[1]);
    assertEquals(0, buf[2]);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor) PageCacheRule(org.neo4j.test.rule.PageCacheRule) Test(org.junit.jupiter.api.Test)

Example 3 with ByteArrayPageCursor

use of org.neo4j.io.pagecache.ByteArrayPageCursor in project neo4j by neo4j.

the class BlockStorage method writeEntries.

private static <KEY, VALUE> long writeEntries(StoreChannel targetChannel, ByteBuffer byteBuffer, Layout<KEY, VALUE> layout, BlockEntryCursor<KEY, VALUE> blockEntryCursor, Cancellation cancellation, IntConsumer entryCountReporter) throws IOException {
    // Loop over block entries
    long actualDataSize = BLOCK_HEADER_SIZE;
    ByteArrayPageCursor pageCursor = new ByteArrayPageCursor(byteBuffer);
    int entryCountToReport = 0;
    while (blockEntryCursor.next()) {
        KEY key = blockEntryCursor.key();
        VALUE value = blockEntryCursor.value();
        int entrySize = BlockEntry.entrySize(layout, key, value);
        actualDataSize += entrySize;
        entryCountToReport++;
        if (byteBuffer.remaining() < entrySize) {
            // First check if this merge have been cancelled, if so just break here, it's fine.
            if (cancellation.cancelled()) {
                break;
            }
            // flush and reset + DON'T PAD!!!
            byteBuffer.flip();
            targetChannel.writeAll(byteBuffer);
            byteBuffer.clear();
            entryCountReporter.accept(entryCountToReport);
            entryCountToReport = 0;
        }
        BlockEntry.write(pageCursor, layout, key, value);
    }
    if (entryCountToReport > 0) {
        entryCountReporter.accept(entryCountToReport);
    }
    return actualDataSize;
}
Also used : ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor)

Example 4 with ByteArrayPageCursor

use of org.neo4j.io.pagecache.ByteArrayPageCursor in project neo4j by neo4j.

the class SimpleEntryStorage method allocateResources.

private void allocateResources() throws IOException {
    if (!allocated) {
        this.scopedBuffer = byteBufferFactory.allocate(blockSize, memoryTracker);
        this.buffer = scopedBuffer.getBuffer();
        this.pageCursor = new ByteArrayPageCursor(buffer);
        this.storeChannel = fs.write(file);
        this.allocated = true;
    }
}
Also used : ByteArrayPageCursor(org.neo4j.io.pagecache.ByteArrayPageCursor)

Aggregations

ByteArrayPageCursor (org.neo4j.io.pagecache.ByteArrayPageCursor)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.jupiter.api.Test)1 ReadAheadChannel (org.neo4j.io.fs.ReadAheadChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 PageCursor (org.neo4j.io.pagecache.PageCursor)1 PageCacheRule (org.neo4j.test.rule.PageCacheRule)1