Search in sources :

Example 1 with RecordingPageCacheTracer

use of org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer 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));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 2 with RecordingPageCacheTracer

use of org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer 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));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 3 with RecordingPageCacheTracer

use of org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer 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));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 4 with RecordingPageCacheTracer

use of org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer 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));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 5 with RecordingPageCacheTracer

use of org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer in project neo4j by neo4j.

the class CommonAbstractStoreTest method recordCursorPinsEachPageItReads.

@Test
public void recordCursorPinsEachPageItReads() throws Exception {
    File storeFile = dir.file("a");
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer pageCursorTracer = new RecordingPageCursorTracer(Pin.class);
    PageCacheRule.PageCacheConfig pageCacheConfig = config().withTracer(tracer).withCursorTracerSupplier(pageCursorTracerSupplier(pageCursorTracer));
    PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get(), pageCacheConfig, Config.empty());
    try (NodeStore store = new NodeStore(storeFile, Config.empty(), new DefaultIdGeneratorFactory(fileSystemRule.get()), pageCache, NullLogProvider.getInstance(), null, Standard.LATEST_RECORD_FORMATS)) {
        store.initialise(true);
        assertNull(tracer.tryObserve(Event.class));
        long nodeId1 = insertNodeRecordAndObservePinEvent(pageCursorTracer, store);
        long nodeId2 = insertNodeRecordAndObservePinEvent(pageCursorTracer, store);
        try (RecordCursor<NodeRecord> cursor = store.newRecordCursor(store.newRecord())) {
            cursor.acquire(0, RecordLoad.NORMAL);
            assertTrue(cursor.next(nodeId1));
            assertTrue(cursor.next(nodeId2));
        }
        // Because both nodes hit the same page, the code will only pin the page once and thus only emit one pin
        // event. This pin event will not be observable until after we have closed the cursor. We could
        // alternatively have chosen nodeId2 to be on a different page than nodeId1. In that case, the pin event
        // for nodeId1 would have been visible after our call to cursor.next( nodeId2 ).
        assertNotNull(pageCursorTracer.tryObserve(Pin.class));
        assertNull(pageCursorTracer.tryObserve(Event.class));
    }
}
Also used : DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Pin(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Pin) Event(org.neo4j.io.pagecache.tracing.recording.Event) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) ConfigurablePageCacheRule(org.neo4j.test.rule.ConfigurablePageCacheRule) PageCacheRule(org.neo4j.test.rule.PageCacheRule) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 PagedFile (org.neo4j.io.pagecache.PagedFile)5 RecordingPageCacheTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer)5 RecordingPageCursorTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer)5 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)4 PageCursor (org.neo4j.io.pagecache.PageCursor)4 ConfigurablePageCursorTracerSupplier (org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier)4 Evict (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict)4 Fault (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault)4 ByteBuffer (java.nio.ByteBuffer)3 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)3 StoreChannel (org.neo4j.io.fs.StoreChannel)3 File (java.io.File)1 PageCache (org.neo4j.io.pagecache.PageCache)1 Event (org.neo4j.io.pagecache.tracing.recording.Event)1 Pin (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Pin)1 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 ConfigurablePageCacheRule (org.neo4j.test.rule.ConfigurablePageCacheRule)1 PageCacheRule (org.neo4j.test.rule.PageCacheRule)1