Search in sources :

Example 11 with DefaultPageCacheTracer

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

the class PageCacheTest method noFaultReadOfPagesNotInMemory.

@Test
void noFaultReadOfPagesNotInMemory() throws Exception {
    DefaultPageCacheTracer cacheTracer = new DefaultPageCacheTracer();
    getPageCache(fs, maxPages, cacheTracer);
    Path file = file("a");
    generateFileWithRecords(file, recordsPerFilePage * 2, recordSize);
    long initialFaults = cacheTracer.faults();
    try (PagedFile pf = map(file, filePageSize);
        CursorContext cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("noFaultReadOfPagesNotInMemory"));
        PageCursor nofault = pf.io(0, PF_SHARED_READ_LOCK | PF_NO_FAULT, cursorContext)) {
        verifyNoFaultAccessToPagesNotInMemory(cacheTracer, cursorContext, nofault, initialFaults);
    }
}
Also used : Path(java.nio.file.Path) 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)

Example 12 with DefaultPageCacheTracer

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

the class PageCacheTest method noFaultLinkedReadOfPagesNotInMemory.

@Test
void noFaultLinkedReadOfPagesNotInMemory() throws Exception {
    DefaultPageCacheTracer cacheTracer = new DefaultPageCacheTracer();
    getPageCache(fs, maxPages, cacheTracer);
    Path file = file("a");
    generateFileWithRecords(file, recordsPerFilePage * 2, recordSize);
    long initialFaults = cacheTracer.faults();
    try (PagedFile pf = map(file, filePageSize);
        CursorContext cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("noFaultLinkedReadOfPagesNotInMemory"));
        PageCursor nofault = pf.io(0, PF_SHARED_READ_LOCK | PF_NO_FAULT, cursorContext);
        PageCursor linkedNoFault = nofault.openLinkedCursor(0)) {
        verifyNoFaultAccessToPagesNotInMemory(cacheTracer, cursorContext, linkedNoFault, initialFaults);
    }
}
Also used : Path(java.nio.file.Path) 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)

Example 13 with DefaultPageCacheTracer

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

the class PageCacheTest method pinEventShouldCompleteIfRepinFromShouldRetryThrows.

@Test
void pinEventShouldCompleteIfRepinFromShouldRetryThrows() throws IOException {
    DefaultPageCacheTracer tracer = new DefaultPageCacheTracer();
    RandomAdversary adversary = new RandomAdversary(0.0, 0.9, 0.0);
    adversary.setProbabilityFactor(0.0);
    AdversarialFileSystemAbstraction afs = new AdversarialFileSystemAbstraction(adversary, fs);
    getPageCache(afs, maxPages, tracer);
    generateFileWithRecords(file("a"), recordCount, recordSize);
    try (PagedFile pagedFile = map(file("a"), filePageSize);
        CursorContext cursorContext = new CursorContext(tracer.createPageCursorTracer("test"))) {
        try (PageCursor reader = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
            assertTrue(reader.next());
            // Cause the page under the reader cursor to be evicted.
            try (PagedFile otherPagedFile = map(existingFile("b"), filePageSize)) {
                assertThrows(IOException.class, () -> {
                    // noinspection InfiniteLoopStatement
                    for (; ; ) {
                        adversary.setProbabilityFactor(1.0);
                        try {
                            reader.shouldRetry();
                        } finally {
                            adversary.setProbabilityFactor(0.0);
                        }
                        try (PageCursor writer = otherPagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
                            for (int i = 0; i < maxPages * 10; i++) {
                                assertTrue(writer.next(i));
                            }
                        }
                        otherPagedFile.flushAndForce();
                    }
                });
            }
        }
    }
    // Then we should see pins and unpins pair up exactly.
    assertThat(tracer.unpins()).isEqualTo(tracer.pins());
}
Also used : CursorContext(org.neo4j.io.pagecache.context.CursorContext) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 14 with DefaultPageCacheTracer

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

the class ReadOnlyLogVersionRepositoryIT method tracePageCacheAccessOnReadOnlyLogRepoConstruction.

@Test
void tracePageCacheAccessOnReadOnlyLogRepoConstruction() throws IOException {
    var pageCacheTracer = new DefaultPageCacheTracer();
    var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnReadOnlyLogRepoConstruction"));
    new ReadOnlyLogVersionRepository(pageCache, databaseLayout, cursorContext);
    PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
    assertThat(cursorTracer.pins()).isEqualTo(2);
    assertThat(cursorTracer.unpins()).isEqualTo(2);
    assertThat(cursorTracer.hits()).isEqualTo(2);
}
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 15 with DefaultPageCacheTracer

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

the class CommitProcessTracingIT method tracePageCacheAccessOnEmptyTransactionApply.

@Test
void tracePageCacheAccessOnEmptyTransactionApply() throws TransactionFailureException {
    var transaction = new PhysicalTransactionRepresentation(emptyList(), EMPTY_BYTE_ARRAY, 0, 0, 0, 0, ANONYMOUS);
    var pageCacheTracer = new DefaultPageCacheTracer();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnEmptyTransactionApply"))) {
        assertZeroCursor(cursorContext);
        commitProcess.commit(new TransactionToApply(transaction, cursorContext), NULL, EXTERNAL);
        assertCursor(cursorContext, 2);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) 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