Search in sources :

Example 96 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class PageCacheByteArray method setByte.

@Override
public void setByte(long index, int offset, byte value) {
    long pageId = pageId(index);
    offset += offset(index);
    try (CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(PAGE_CACHE_BYTE_ARRAY_WORKER_TAG));
        PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK | PF_NO_GROW, cursorContext)) {
        cursor.next();
        cursor.putByte(offset, value);
        checkBounds(cursor);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 97 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class PageCacheByteArray method set6ByteLong.

@Override
public void set6ByteLong(long index, int offset, long value) {
    long pageId = pageId(index);
    offset += offset(index);
    try (CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(PAGE_CACHE_BYTE_ARRAY_WORKER_TAG));
        PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK | PF_NO_GROW, cursorContext)) {
        cursor.next();
        cursor.putInt(offset, (int) value);
        cursor.putShort(offset + Integer.BYTES, (short) (value >>> Integer.SIZE));
        checkBounds(cursor);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 98 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class PageCacheByteArray method getByte.

@Override
public byte getByte(long index, int offset) {
    long pageId = pageId(index);
    offset += offset(index);
    try (CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(PAGE_CACHE_BYTE_ARRAY_WORKER_TAG));
        PageCursor cursor = pagedFile.io(pageId, PF_SHARED_READ_LOCK, cursorContext)) {
        cursor.next();
        byte result;
        do {
            result = cursor.getByte(offset);
        } while (cursor.shouldRetry());
        checkBounds(cursor);
        return result;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 99 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class PageCacheByteArray method get6ByteLong.

@Override
public long get6ByteLong(long index, int offset) {
    long pageId = pageId(index);
    offset += offset(index);
    try (CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(PAGE_CACHE_BYTE_ARRAY_WORKER_TAG));
        PageCursor cursor = pagedFile.io(pageId, PF_SHARED_READ_LOCK, cursorContext)) {
        cursor.next();
        long result;
        do {
            long low4b = cursor.getInt(offset) & 0xFFFFFFFFL;
            long high2b = cursor.getShort(offset + Integer.BYTES) & 0xFFFF;
            result = low4b | (high2b << Integer.SIZE);
        } while (cursor.shouldRetry());
        checkBounds(cursor);
        return result == 0xFFFFFFFFFFFFL ? -1 : result;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 100 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class PageCacheByteArray method swap.

@Override
public void swap(long fromIndex, long toIndex) {
    long fromPageId = pageId(fromIndex);
    int fromOffset = offset(fromIndex);
    long toPageId = pageId(toIndex);
    int toOffset = offset(toIndex);
    try (CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(PAGE_CACHE_BYTE_ARRAY_WORKER_TAG));
        PageCursor fromCursor = pagedFile.io(fromPageId, PF_SHARED_WRITE_LOCK, cursorContext);
        PageCursor toCursor = pagedFile.io(toPageId, PF_SHARED_WRITE_LOCK, cursorContext)) {
        fromCursor.next();
        toCursor.next();
        for (int i = 0; i < entrySize; i++, fromOffset++, toOffset++) {
            byte intermediary = fromCursor.getByte(fromOffset);
            fromCursor.putByte(fromOffset, toCursor.getByte(toOffset));
            toCursor.putByte(toOffset, intermediary);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

CursorContext (org.neo4j.io.pagecache.context.CursorContext)161 Test (org.junit.jupiter.api.Test)74 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)52 PageCursor (org.neo4j.io.pagecache.PageCursor)40 IOException (java.io.IOException)31 UncheckedIOException (java.io.UncheckedIOException)27 PageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer)27 Path (java.nio.file.Path)17 PagedFile (org.neo4j.io.pagecache.PagedFile)17 ArrayList (java.util.ArrayList)16 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)15 MutableLong (org.apache.commons.lang3.mutable.MutableLong)13 MemoryTracker (org.neo4j.memory.MemoryTracker)12 PageCache (org.neo4j.io.pagecache.PageCache)11 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)10 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)10 List (java.util.List)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8