Search in sources :

Example 6 with NativeScopedBuffer

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();
}
Also used : Path(java.nio.file.Path) StoreChannel(org.neo4j.io.fs.StoreChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) Test(org.junit.jupiter.api.Test)

Example 7 with NativeScopedBuffer

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);
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) NativeMemoryAllocationRefusedError(org.neo4j.internal.unsafe.NativeMemoryAllocationRefusedError)

Aggregations

NativeScopedBuffer (org.neo4j.io.memory.NativeScopedBuffer)7 ReadAheadChannel (org.neo4j.io.fs.ReadAheadChannel)2 ReadPastEndException (org.neo4j.io.fs.ReadPastEndException)2 PositionAwarePhysicalFlushableChecksumChannel (org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChecksumChannel)2 LogRotationMonitor (org.neo4j.kernel.impl.transaction.log.rotation.monitor.LogRotationMonitor)2 ByteBuffer (java.nio.ByteBuffer)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1 NativeMemoryAllocationRefusedError (org.neo4j.internal.unsafe.NativeMemoryAllocationRefusedError)1 ReadableChannel (org.neo4j.io.fs.ReadableChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)1 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)1 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)1 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)1 DetachedCheckpointLogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.DetachedCheckpointLogEntryWriter)1 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)1