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);
}
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]);
}
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;
}
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;
}
}
Aggregations