use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.
the class PhysicalFlushableChannelTest method shouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel.
@Test
void shouldSeeCorrectPositionEvenBeforeEmptyingDataIntoChannel() throws Exception {
// GIVEN
final Path file = directory.homePath().resolve("file");
StoreChannel storeChannel = fileSystem.write(file);
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, (byte) -1, file, nativeChannelAccessor);
PositionAwarePhysicalFlushableChecksumChannel channel = new PositionAwarePhysicalFlushableChecksumChannel(versionedStoreChannel, new NativeScopedBuffer(1024, INSTANCE));
LogPosition initialPosition = channel.getCurrentPosition();
// WHEN
channel.putLong(67);
channel.putInt(1234);
LogPosition positionAfterSomeData = channel.getCurrentPosition();
// THEN
assertEquals(12, positionAfterSomeData.getByteOffset() - initialPosition.getByteOffset());
channel.close();
}
use of org.neo4j.io.memory.NativeScopedBuffer in project neo4j by neo4j.
the class UnsafeDirectByteBufferAllocator method allocate.
@Override
public synchronized ScopedBuffer allocate(int bufferSize, MemoryTracker memoryTracker) {
assertOpen();
try {
var byteBuffer = new NativeScopedBuffer(bufferSize, memoryTracker);
allocations.add(byteBuffer);
return byteBuffer;
} catch (NativeMemoryAllocationRefusedError allocationRefusedError) {
// What ever went wrong fallback to on-heap buffer.
return new HeapScopedBuffer(bufferSize, memoryTracker);
}
}
Aggregations