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