Search in sources :

Example 6 with DefaultPageCacheTracer

use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.

the class StoreUpgraderTest method tracePageCacheAccessOnStoreUpgrade.

@ParameterizedTest
@MethodSource("versions")
void tracePageCacheAccessOnStoreUpgrade(RecordFormats formats) throws IOException {
    init(formats);
    fileSystem.deleteFile(databaseLayout.file(INTERNAL_LOG_FILE));
    StoreVersionCheck check = getVersionCheck(pageCache);
    var pageCacheTracer = new DefaultPageCacheTracer();
    newUpgrader(check, allowMigrateConfig, pageCache, pageCacheTracer).migrateIfNeeded(databaseLayout, false);
    assertThat(pageCacheTracer.hits()).isGreaterThan(0);
    assertThat(pageCacheTracer.pins()).isGreaterThan(0);
    assertThat(pageCacheTracer.unpins()).isGreaterThan(0);
    assertThat(pageCacheTracer.faults()).isGreaterThan(0);
    StoreFactory factory = new StoreFactory(databaseLayout, allowMigrateConfig, new ScanOnOpenOverwritingIdGeneratorFactory(fileSystem, databaseLayout.getDatabaseName()), pageCache, fileSystem, NullLogProvider.getInstance(), NULL, writable());
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        assertThat(neoStores.getMetaDataStore().getUpgradeTransaction()).isEqualTo(neoStores.getMetaDataStore().getLastCommittedTransaction());
        assertThat(neoStores.getMetaDataStore().getUpgradeTime()).isPositive();
    }
}
Also used : StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) ScanOnOpenOverwritingIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with DefaultPageCacheTracer

use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.

the class FullScanNonUniqueIndexSamplerTest method tracePageCacheAccessOnSampling.

@Test
void tracePageCacheAccessOnSampling() throws IOException {
    Value[] values = generateNumberValues();
    buildTree(values);
    var pageCacheTracer = new DefaultPageCacheTracer();
    var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("testTracer"));
    assertZeroCursor(cursorContext);
    try (GBPTree<GenericKey, NativeIndexValue> gbpTree = getTree()) {
        FullScanNonUniqueIndexSampler<GenericKey, NativeIndexValue> sampler = new FullScanNonUniqueIndexSampler<>(gbpTree, layout);
        sampler.sample(cursorContext);
    }
    PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
    assertThat(cursorTracer.pins()).isEqualTo(1);
    assertThat(cursorTracer.unpins()).isEqualTo(1);
    assertThat(cursorTracer.faults()).isEqualTo(1);
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) Value(org.neo4j.values.storable.Value) NumberValue(org.neo4j.values.storable.NumberValue) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 8 with DefaultPageCacheTracer

use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.

the class IndexStatisticsStoreTest method tracePageCacheAccessOnCheckpoint.

@Test
void tracePageCacheAccessOnCheckpoint() throws IOException {
    var cacheTracer = new DefaultPageCacheTracer();
    var store = openStore(cacheTracer, "checkpoint");
    try (var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnCheckpoint"))) {
        for (int i = 0; i < 100; i++) {
            store.replaceStats(i, new IndexSample());
        }
        store.checkpoint(cursorContext);
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        assertThat(cursorTracer.pins()).isEqualTo(43);
        assertThat(cursorTracer.unpins()).isEqualTo(43);
        assertThat(cursorTracer.hits()).isEqualTo(35);
        assertThat(cursorTracer.faults()).isEqualTo(8);
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultPageCacheTracer

use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.

the class IndexStatisticsStoreTest method tracePageCacheAccessOnConsistencyCheck.

@Test
void tracePageCacheAccessOnConsistencyCheck() throws IOException {
    var cacheTracer = new DefaultPageCacheTracer();
    var store = openStore(cacheTracer, "consistencyCheck");
    try (var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnConsistencyCheck"))) {
        for (int i = 0; i < 100; i++) {
            store.replaceStats(i, new IndexSample());
        }
        store.checkpoint(CursorContext.NULL);
        store.consistencyCheck(noopReporterFactory(), cursorContext);
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        assertThat(cursorTracer.pins()).isEqualTo(16);
        assertThat(cursorTracer.unpins()).isEqualTo(16);
        assertThat(cursorTracer.hits()).isEqualTo(16);
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 10 with DefaultPageCacheTracer

use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.

the class PageCacheTest method tracerMustBeNotifiedAboutPinUnpinFaultAndEvictEventsWhenReading.

@Test
void tracerMustBeNotifiedAboutPinUnpinFaultAndEvictEventsWhenReading() {
    assertTimeoutPreemptively(ofMillis(SHORT_TIMEOUT_MILLIS), () -> {
        DefaultPageCacheTracer tracer = new DefaultPageCacheTracer();
        getPageCache(fs, maxPages, tracer);
        generateFileWithRecords(file("a"), recordCount, recordSize);
        long initialPins = tracer.pins();
        long initialUnpins = tracer.unpins();
        long countedPages = 0;
        long countedFaults = 0;
        try (CursorContext cursorContext = new CursorContext(tracer.createPageCursorTracer("tracerMustBeNotifiedAboutPinUnpinFaultAndEvictEventsWhenReading"));
            PagedFile pagedFile = map(file("a"), filePageSize);
            PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
            while (cursor.next()) {
                countedPages++;
                countedFaults++;
            }
            // Using next( pageId ) to the already-pinned page id does not count,
            // so we only increment once for this section
            countedPages++;
            for (int i = 0; i < 20; i++) {
                assertTrue(cursor.next(1));
            }
            // then it counts
            for (int i = 0; i < 20; i++) {
                assertTrue(cursor.next(i));
                countedPages++;
            }
        }
        assertThat(tracer.pins()).as("wrong count of pins").isEqualTo(countedPages + initialPins);
        assertThat(tracer.unpins()).as("wrong count of unpins").isEqualTo(countedPages + initialUnpins);
        // We might be unlucky and fault in the second next call, on the page
        // we brought up in the first next call. That's why we assert that we
        // have observed *at least* the countedPages number of faults.
        long faults = tracer.faults();
        long bytesRead = tracer.bytesRead();
        assertThat(faults).as("wrong count of faults").isGreaterThanOrEqualTo(countedFaults);
        assertThat(bytesRead).as("wrong number of bytes read").isGreaterThanOrEqualTo(countedFaults * filePageSize);
        // Every page we move forward can put the freelist behind so the cache
        // wants to evict more pages. Plus, every page fault we do could also
        // block and get a page directly transferred to it, and these kinds of
        // evictions can count in addition to the evictions we do when the
        // cache is behind on keeping the freelist full.
        assertThat(tracer.evictions()).as("wrong count of evictions").isGreaterThanOrEqualTo(countedFaults - maxPages).isLessThanOrEqualTo(countedPages + faults);
    });
}
Also used : CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)79 Test (org.junit.jupiter.api.Test)66 CursorContext (org.neo4j.io.pagecache.context.CursorContext)49 PageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer)26 Path (java.nio.file.Path)11 RepeatedTest (org.junit.jupiter.api.RepeatedTest)10 MutableLong (org.apache.commons.lang3.mutable.MutableLong)9 Transaction (org.neo4j.graphdb.Transaction)9 PageCache (org.neo4j.io.pagecache.PageCache)9 Test (org.junit.Test)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 DelegatingPageCache (org.neo4j.io.pagecache.DelegatingPageCache)5 PagedFile (org.neo4j.io.pagecache.PagedFile)5 Config (org.neo4j.configuration.Config)3 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)3 PageCursor (org.neo4j.io.pagecache.PageCursor)3 PageCacheStressTest (org.neo4j.io.pagecache.stress.PageCacheStressTest)3 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)3 DefaultPageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracer)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3