Search in sources :

Example 1 with Event

use of org.neo4j.io.pagecache.tracing.recording.Event 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

File (java.io.File)1 Test (org.junit.Test)1 PageCache (org.neo4j.io.pagecache.PageCache)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 Event (org.neo4j.io.pagecache.tracing.recording.Event)1 RecordingPageCacheTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer)1 RecordingPageCursorTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer)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