use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class PageCacheTest method noFaultWriteOnPagesNotInMemory.
@Test
void noFaultWriteOnPagesNotInMemory() throws Exception {
DefaultPageCacheTracer cacheTracer = new DefaultPageCacheTracer();
getPageCache(fs, maxPages, cacheTracer);
Path file = file("a");
generateFileWithRecords(file, recordsPerFilePage * 2, recordSize);
long initialFaults = cacheTracer.faults();
try (PagedFile pf = map(file, filePageSize);
CursorContext cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("noFaultWriteOnPagesNotInMemory"));
PageCursor nofault = pf.io(0, PF_SHARED_WRITE_LOCK | PF_NO_FAULT, cursorContext)) {
verifyNoFaultAccessToPagesNotInMemory(cacheTracer, cursorContext, nofault, initialFaults);
verifyNoFaultWriteIsOutOfBounds(nofault);
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method pageModificationTrackingNoticeWriteFromAnotherThread.
@Test
void pageModificationTrackingNoticeWriteFromAnotherThread() throws Exception {
TestVersionContext versionContext = new TestVersionContext(() -> 0);
CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext);
try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
versionContext.initWrite(7);
Future<?> future = executor.submit(() -> {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next());
cursor.putLong(1);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
future.get();
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
assertTrue(cursor.next());
MuninnPageCursor pageCursor = (MuninnPageCursor) cursor;
assertEquals(7, pageCursor.pagedFile.getLastModifiedTxId(pageCursor.pinnedPageRef));
assertEquals(1, cursor.getLong());
}
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingFirstPage.
@Test
void mustFlushDirtyPagesOnEvictingFirstPage() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorContext = new RecordingPageCursorTracer(tracer, "mustFlushDirtyPagesOnEvictingFirstPage");
try (MuninnPageCache pageCache = createPageCache(fs, 2, blockCacheFlush(tracer));
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, new CursorContext(cursorContext))) {
assertTrue(cursor.next());
cursor.putLong(0L);
}
cursorContext.reportEvents();
assertNotNull(cursorContext.observe(Fault.class));
assertEquals(1, cursorContext.faults());
assertEquals(1, tracer.faults());
long clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
assertThat(clockArm).isEqualTo(1L);
assertNotNull(tracer.observe(Evict.class));
ByteBuffer buf = readIntoBuffer("a");
assertThat(buf.getLong()).isEqualTo(0L);
assertThat(buf.getLong()).isEqualTo(y);
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method mustEvictCleanPageWithoutFlushing.
@Test
void mustEvictCleanPageWithoutFlushing() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorContext = new RecordingPageCursorTracer(tracer, "mustEvictCleanPageWithoutFlushing");
try (MuninnPageCache pageCache = createPageCache(fs, 2, blockCacheFlush(tracer));
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, new CursorContext(cursorContext))) {
assertTrue(cursor.next());
}
cursorContext.reportEvents();
assertNotNull(cursorContext.observe(Fault.class));
assertEquals(1, cursorContext.faults());
assertEquals(1, tracer.faults());
long clockArm = pageCache.evictPages(1, 1, tracer.beginPageEvictions(1));
assertThat(clockArm).isEqualTo(1L);
assertNotNull(tracer.observe(Evict.class));
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method markCursorContextDirtyWhenRepositionCursorOnItsCurrentPage.
@Test
void markCursorContextDirtyWhenRepositionCursorOnItsCurrentPage() throws IOException {
TestVersionContext versionContext = new TestVersionContext(() -> 3);
CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext);
try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
versionContext.initRead();
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next(0));
assertFalse(versionContext.isDirty());
MuninnPageCursor pageCursor = (MuninnPageCursor) cursor;
pageCursor.pagedFile.setLastModifiedTxId(((MuninnPageCursor) cursor).pinnedPageRef, 17);
assertTrue(cursor.next(0));
assertTrue(versionContext.isDirty());
}
}
}
Aggregations