use of org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingAllPages.
@Test
public void mustFlushDirtyPagesOnEvictingAllPages() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer(Fault.class);
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
MuninnPageCache pageCache = createPageCache(fs, 4, 8, blockCacheFlush(tracer), cursorTracerSupplier);
PagedFile pagedFile = pageCache.map(file("a"), 8);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK | PF_NO_GROW)) {
assertTrue(cursor.next());
cursor.putLong(0L);
assertTrue(cursor.next());
cursor.putLong(0L);
assertFalse(cursor.next());
}
cursorTracer.reportEvents();
assertNotNull(cursorTracer.observe(Fault.class));
assertNotNull(cursorTracer.observe(Fault.class));
assertEquals(2, cursorTracer.faults());
assertEquals(2, tracer.faults());
int clockArm = pageCache.evictPages(2, 0, tracer.beginPageEvictions(2));
assertThat(clockArm, is(2));
assertNotNull(tracer.observe(Evict.class));
assertNotNull(tracer.observe(Evict.class));
ByteBuffer buf = ByteBuffer.allocate(16);
StoreChannel channel = fs.open(file("a"), "r");
channel.read(buf);
buf.flip();
assertThat(buf.getLong(), is(0L));
assertThat(buf.getLong(), is(0L));
}
use of org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier in project neo4j by neo4j.
the class PageCacheTest method tracerMustBeNotifiedOfReadAndWritePins.
@Test
public void tracerMustBeNotifiedOfReadAndWritePins() throws Exception {
final AtomicInteger writeCount = new AtomicInteger();
final AtomicInteger readCount = new AtomicInteger();
DefaultPageCacheTracer tracer = new DefaultPageCacheTracer();
DefaultPageCursorTracer pageCursorTracer = new DefaultPageCursorTracer() {
@Override
public PinEvent beginPin(boolean writeLock, long filePageId, PageSwapper swapper) {
(writeLock ? writeCount : readCount).getAndIncrement();
return super.beginPin(writeLock, filePageId, swapper);
}
};
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(pageCursorTracer);
generateFileWithRecords(file("a"), recordCount, recordSize);
getPageCache(fs, maxPages, pageCachePageSize, tracer, cursorTracerSupplier);
int pinsForRead = 13;
int pinsForWrite = 42;
try (PagedFile pagedFile = pageCache.map(file("a"), filePageSize)) {
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK)) {
for (int i = 0; i < pinsForRead; i++) {
assertTrue(cursor.next());
}
}
dirtyManyPages(pagedFile, pinsForWrite);
}
assertThat("wrong read pin count", readCount.get(), is(pinsForRead));
assertThat("wrong write pin count", writeCount.get(), is(pinsForWrite));
}
use of org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingFirstPage.
@Test
public void mustFlushDirtyPagesOnEvictingFirstPage() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
PagedFile pagedFile = pageCache.map(file("a"), 8);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
assertTrue(cursor.next());
cursor.putLong(0L);
}
cursorTracer.reportEvents();
assertNotNull(cursorTracer.observe(Fault.class));
assertEquals(1, cursorTracer.faults());
assertEquals(1, tracer.faults());
int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
assertThat(clockArm, is(1));
assertNotNull(tracer.observe(Evict.class));
ByteBuffer buf = ByteBuffer.allocate(16);
StoreChannel channel = fs.open(file("a"), "r");
channel.read(buf);
buf.flip();
assertThat(buf.getLong(), is(0L));
assertThat(buf.getLong(), is(y));
}
use of org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier in project neo4j by neo4j.
the class MuninnPageCacheTest method mustEvictCleanPageWithoutFlushing.
@Test
public void mustEvictCleanPageWithoutFlushing() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
PagedFile pagedFile = pageCache.map(file("a"), 8);
try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK)) {
assertTrue(cursor.next());
}
cursorTracer.reportEvents();
assertNotNull(cursorTracer.observe(Fault.class));
assertEquals(1, cursorTracer.faults());
assertEquals(1, tracer.faults());
int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
assertThat(clockArm, is(1));
assertNotNull(tracer.observe(Evict.class));
}
use of org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier in project neo4j by neo4j.
the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingLastPage.
@Test
public void mustFlushDirtyPagesOnEvictingLastPage() throws Exception {
writeInitialDataTo(file("a"));
RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
PagedFile pagedFile = pageCache.map(file("a"), 8);
try (PageCursor cursor = pagedFile.io(1, PF_SHARED_WRITE_LOCK)) {
assertTrue(cursor.next());
cursor.putLong(0L);
}
cursorTracer.reportEvents();
assertNotNull(cursorTracer.observe(Fault.class));
assertEquals(1, cursorTracer.faults());
assertEquals(1, tracer.faults());
int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
assertThat(clockArm, is(1));
assertNotNull(tracer.observe(Evict.class));
ByteBuffer buf = ByteBuffer.allocate(16);
StoreChannel channel = fs.open(file("a"), "r");
channel.read(buf);
buf.flip();
assertThat(buf.getLong(), is(x));
assertThat(buf.getLong(), is(0L));
}
Aggregations