use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingAllPages.
@Test
void mustFlushDirtyPagesOnEvictingAllPages() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorContext = new RecordingPageCursorTracer(tracer, "mustFlushDirtyPagesOnEvictingAllPages", Fault.class);
try (MuninnPageCache pageCache = createPageCache(fs, 4, blockCacheFlush(tracer));
PagedFile pagedFile = map(pageCache, file("a"), 8)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK | PF_NO_GROW, new CursorContext(cursorContext))) {
assertTrue(cursor.next());
cursor.putLong(0L);
assertTrue(cursor.next());
cursor.putLong(0L);
assertFalse(cursor.next());
}
cursorContext.reportEvents();
assertNotNull(cursorContext.observe(Fault.class));
assertNotNull(cursorContext.observe(Fault.class));
assertEquals(2, cursorContext.faults());
assertEquals(2, tracer.faults());
long clockArm = pageCache.evictPages(2, 0, tracer.beginPageEvictions(2));
assertThat(clockArm).isEqualTo(2L);
assertNotNull(tracer.observe(Evict.class));
assertNotNull(tracer.observe(Evict.class));
ByteBuffer buf = readIntoBuffer("a");
assertThat(buf.getLong()).isEqualTo(0L);
assertThat(buf.getLong()).isEqualTo(0L);
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method trackPageModificationTransactionId.
@Test
void trackPageModificationTransactionId() throws Exception {
TestVersionContext versionContext = new TestVersionContext(() -> 0);
try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
PagedFile pagedFile = map(pageCache, file("a"), 8);
CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext)) {
versionContext.initWrite(7);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next());
cursor.putLong(1);
}
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 markContextAsDirtyWhenAnyEvictedPageHaveModificationTransactionHigherThenReader.
@Test
void markContextAsDirtyWhenAnyEvictedPageHaveModificationTransactionHigherThenReader() throws IOException {
TestVersionContext versionContext = new TestVersionContext(() -> 5);
try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
PagedFile pagedFile = map(pageCache, file("a"), 8);
CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext)) {
versionContext.initWrite(3);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next());
cursor.putLong(3);
}
versionContext.initWrite(13);
try (PageCursor cursor = pagedFile.io(1, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next());
cursor.putLong(4);
}
evictAllPages(pageCache);
versionContext.initRead();
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
assertTrue(cursor.next());
assertEquals(3, cursor.getLong());
assertTrue(versionContext.isDirty());
}
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method shouldBeAbleToSetDeleteOnCloseFileAfterItWasMapped.
@Test
void shouldBeAbleToSetDeleteOnCloseFileAfterItWasMapped() throws IOException {
DefaultPageCacheTracer defaultPageCacheTracer = new DefaultPageCacheTracer();
Path fileForDeletion = file("fileForDeletion");
writeInitialDataTo(fileForDeletion);
long initialFlushes = defaultPageCacheTracer.flushes();
try (MuninnPageCache pageCache = createPageCache(fs, 2, defaultPageCacheTracer)) {
try (var cursorContext = new CursorContext(defaultPageCacheTracer.createPageCursorTracer("shouldBeAbleToSetDeleteOnCloseFileAfterItWasMapped"));
PagedFile pagedFile = map(pageCache, fileForDeletion, 8)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next());
cursor.putLong(0L);
}
pagedFile.setDeleteOnClose(true);
}
assertFalse(fs.fileExists(fileForDeletion));
assertEquals(0, defaultPageCacheTracer.flushes() - initialFlushes);
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class MuninnPageCacheTest method reportFreeListSizeToTracers.
@Test
void reportFreeListSizeToTracers() throws IOException {
var pageCacheTracer = new InfoTracer();
try (MuninnPageCache pageCache = createPageCache(fs, 10, pageCacheTracer);
PagedFile pagedFile = map(pageCache, file("a"), (int) ByteUnit.kibiBytes(8))) {
for (int pageId = 0; pageId < 5; pageId++) {
CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("test"));
try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK, cursorContext)) {
assertTrue(cursor.next());
cursor.putLong(1);
}
assertEquals(10 - (pageId + 1), pageCacheTracer.getFreeListSize());
}
pagedFile.flushAndForce();
}
}
Aggregations