Search in sources :

Example 26 with CursorContext

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

the class GBPTreeGenericCountsStoreTest method shouldNotRebuildOnMismatchingLastCommittedTxIdButMatchingAfterRecovery.

@Test
void shouldNotRebuildOnMismatchingLastCommittedTxIdButMatchingAfterRecovery() throws IOException {
    // given some pre-state
    long countsStoreTxId = BASE_TX_ID + 1;
    CountsKey key = nodeKey(1);
    try (CountUpdater updater = countsStore.updater(countsStoreTxId, NULL)) {
        updater.increment(key, 1);
    }
    // leaving a gap intentionally
    try (CountUpdater updater = countsStore.updater(countsStoreTxId + 2, NULL)) {
        updater.increment(key, 3);
    }
    countsStore.checkpoint(NULL);
    // when
    closeCountsStore();
    MutableBoolean rebuildTriggered = new MutableBoolean();
    instantiateCountsStore(new Rebuilder() {

        @Override
        public long lastCommittedTxId() {
            return countsStoreTxId + 2;
        }

        @Override
        public void rebuild(CountUpdater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
            rebuildTriggered.setTrue();
        }
    }, writable(), NO_MONITOR);
    // and do recovery
    try (CountUpdater updater = countsStore.updater(countsStoreTxId + 1, NULL)) {
        updater.increment(key, 7);
    }
    // already applied
    assertThat(countsStore.updater(countsStoreTxId + 2, NULL)).isNull();
    countsStore.start(NULL, INSTANCE);
    // then
    assertThat(rebuildTriggered.booleanValue()).isFalse();
    assertThat(countsStore.read(key, NULL)).isEqualTo(11);
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Rebuilder(org.neo4j.internal.counts.GBPTreeGenericCountsStore.Rebuilder) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test)

Example 27 with CursorContext

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

the class PageCacheByteArray method getInt.

@Override
public int getInt(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();
        int result;
        do {
            result = cursor.getInt(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 28 with CursorContext

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

the class PageCacheByteArray method getLong.

@Override
public long getLong(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 {
            result = cursor.getLong(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 29 with CursorContext

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

the class PageCacheByteArray method setInt.

@Override
public void setInt(long index, int offset, int 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, 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 30 with CursorContext

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

the class PageCacheByteArray method get3ByteInt.

@Override
public int get3ByteInt(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();
        int result;
        do {
            int lowWord = cursor.getShort(offset) & 0xFFFF;
            int highByte = cursor.getByte(offset + Short.BYTES) & 0xFF;
            result = lowWord | (highByte << Short.SIZE);
        } while (cursor.shouldRetry());
        checkBounds(cursor);
        return result == 0xFFFFFF ? -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)

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