Search in sources :

Example 1 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method tracePageCacheAccessOnIndexUpdatesApply.

@ParameterizedTest
@MethodSource("parameters")
void tracePageCacheAccessOnIndexUpdatesApply(GraphDatabaseSettings.SchemaIndex schemaIndex) throws KernelException {
    setUp(schemaIndex);
    var marker = Label.label("marker");
    var propertyName = "property";
    var testConstraint = "testConstraint";
    try (Transaction transaction = database.beginTx()) {
        transaction.schema().constraintFor(marker).withName(testConstraint).assertPropertyIsUnique(propertyName).create();
        transaction.commit();
    }
    var dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    var indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    var pageCacheTracer = dependencyResolver.resolveDependency(PageCacheTracer.class);
    try (Transaction transaction = database.beginTx()) {
        var kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
        var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(testConstraint);
        try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnIndexUpdatesApply"))) {
            Iterable<IndexEntryUpdate<IndexDescriptor>> updates = List.of(add(1, indexDescriptor, longValue(4)));
            indexingService.applyUpdates(updates, cursorContext);
            PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
            assertEquals(5L, cursorTracer.pins());
            assertEquals(5L, cursorTracer.unpins());
            assertEquals(2L, cursorTracer.hits());
            assertEquals(3L, cursorTracer.faults());
        }
    }
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CursorContext(org.neo4j.io.pagecache.context.CursorContext) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class NeoStoresTest method tracePageCacheAccessOnTransactionCloseCall.

@Test
void tracePageCacheAccessOnTransactionCloseCall() {
    StoreFactory factory = getStoreFactory(Config.defaults(), databaseLayout, fs, LOG_PROVIDER);
    try (NeoStores neoStore = factory.openAllNeoStores(true)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        var cacheTracer = new DefaultPageCacheTracer();
        var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnTransactionCloseCall"));
        store.transactionClosed(store.nextCommittingTransactionId(), 6666, 15, cursorContext);
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        assertEquals(1, cursorTracer.pins());
        assertEquals(1, cursorTracer.hits());
        assertEquals(1, cursorTracer.unpins());
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 3 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class NeoStoresIT method tracePageCacheAccessOnUpdateRecord.

@Test
void tracePageCacheAccessOnUpdateRecord() {
    var storageEngine = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
    var neoStores = storageEngine.testAccessNeoStores();
    var nodeStore = neoStores.getNodeStore();
    long nodeId;
    try (Transaction transaction = db.beginTx()) {
        var node = transaction.createNode();
        node.setProperty("a", "b");
        nodeId = node.getId();
        transaction.commit();
    }
    var cursorContext = new CursorContext(new DefaultPageCacheTracer().createPageCursorTracer("tracePageCacheAccessOnUpdateRecord"));
    nodeStore.updateRecord(new NodeRecord(nodeId), cursorContext);
    PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
    assertEquals(5, cursorTracer.hits());
    assertEquals(6, cursorTracer.pins());
    assertEquals(6, cursorTracer.unpins());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) Transaction(org.neo4j.graphdb.Transaction) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 4 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class NeoStoresIT method tracePageCacheAccessOnHighIdScan.

@Test
void tracePageCacheAccessOnHighIdScan() {
    var storageEngine = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
    var neoStores = storageEngine.testAccessNeoStores();
    var propertyStore = neoStores.getPropertyStore();
    for (int i = 0; i < 1000; i++) {
        try (Transaction transaction = db.beginTx()) {
            var node = transaction.createNode();
            node.setProperty("a", randomAscii(1024));
            transaction.commit();
        }
    }
    var cursorContext = new CursorContext(new DefaultPageCacheTracer().createPageCursorTracer("tracePageCacheAccessOnHighIdScan"));
    propertyStore.scanForHighId(cursorContext);
    PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
    assertEquals(1, cursorTracer.hits());
    assertEquals(1, cursorTracer.pins());
    assertEquals(1, cursorTracer.unpins());
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) Transaction(org.neo4j.graphdb.Transaction) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 5 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class NeoStoresIT method tracePageCacheAccessOnGetRawRecordData.

@Test
void tracePageCacheAccessOnGetRawRecordData() throws IOException {
    var storageEngine = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
    var neoStores = storageEngine.testAccessNeoStores();
    var propertyStore = neoStores.getPropertyStore();
    try (Transaction transaction = db.beginTx()) {
        var node = transaction.createNode();
        node.setProperty("a", "b");
        transaction.commit();
    }
    var cursorContext = new CursorContext(new DefaultPageCacheTracer().createPageCursorTracer("tracePageCacheAccessOnGetRawRecordData"));
    propertyStore.getRawRecordData(1L, cursorContext);
    PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
    assertEquals(1, cursorTracer.hits());
    assertEquals(1, cursorTracer.pins());
    assertEquals(1, cursorTracer.unpins());
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) Transaction(org.neo4j.graphdb.Transaction) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Aggregations

CursorContext (org.neo4j.io.pagecache.context.CursorContext)161 Test (org.junit.jupiter.api.Test)74 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)52 PageCursor (org.neo4j.io.pagecache.PageCursor)40 IOException (java.io.IOException)31 UncheckedIOException (java.io.UncheckedIOException)27 PageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer)27 Path (java.nio.file.Path)17 PagedFile (org.neo4j.io.pagecache.PagedFile)17 ArrayList (java.util.ArrayList)16 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)15 MutableLong (org.apache.commons.lang3.mutable.MutableLong)13 MemoryTracker (org.neo4j.memory.MemoryTracker)12 PageCache (org.neo4j.io.pagecache.PageCache)11 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)10 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)10 List (java.util.List)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8