Search in sources :

Example 36 with DefaultPageCacheTracer

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

the class PageCacheTest method noFaultLinkedWriteOnPagesNotInMemory.

@Test
void noFaultLinkedWriteOnPagesNotInMemory() 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("noFaultLinkedWriteOnPagesNotInMemory"));
        PageCursor nofault = pf.io(0, PF_SHARED_WRITE_LOCK | PF_NO_FAULT, cursorContext);
        PageCursor linkedNoFault = nofault.openLinkedCursor(0)) {
        verifyNoFaultAccessToPagesNotInMemory(cacheTracer, cursorContext, linkedNoFault, initialFaults);
        verifyNoFaultWriteIsOutOfBounds(linkedNoFault);
    }
}
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 37 with DefaultPageCacheTracer

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

the class PageCacheTest method noFaultWriteOnPagesNotInMemory.

@Test
void noFaultWriteOnPagesNotInMemory() 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("noFaultWriteOnPagesNotInMemory"));
        PageCursor nofault = pf.io(0, PF_SHARED_WRITE_LOCK | PF_NO_FAULT, cursorContext)) {
        verifyNoFaultAccessToPagesNotInMemory(cacheTracer, cursorContext, nofault, initialFaults);
        verifyNoFaultWriteIsOutOfBounds(nofault);
    }
}
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 38 with DefaultPageCacheTracer

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

the class MuninnPageCacheTest method doNotMergeNonSequentialPageBuffersOnPageFileFlush.

@Test
void doNotMergeNonSequentialPageBuffersOnPageFileFlush() throws IOException {
    var pageCacheTracer = new DefaultPageCacheTracer();
    try (MuninnPageCache pageCache = createPageCache(fs, 6, pageCacheTracer);
        PagedFile pagedFile = map(pageCache, file("a"), (int) ByteUnit.kibiBytes(8))) {
        try (PageCursor cursor = pagedFile.io(1, PF_SHARED_WRITE_LOCK, NULL)) {
            assertTrue(cursor.next());
            cursor.putLong(1);
        }
        try (PageCursor cursor = pagedFile.io(3, PF_SHARED_WRITE_LOCK, NULL)) {
            assertTrue(cursor.next());
            cursor.putLong(1);
        }
        pagedFile.flushAndForce();
        assertEquals(2, pageCacheTracer.flushes());
        assertEquals(0, pageCacheTracer.merges());
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 39 with DefaultPageCacheTracer

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

the class PageCacheTest method tracerMustBeNotifiedAboutPinUnpinFaultFlushAndEvictionEventsWhenWriting.

@Test
void tracerMustBeNotifiedAboutPinUnpinFaultFlushAndEvictionEventsWhenWriting() {
    assertTimeoutPreemptively(ofMillis(SHORT_TIMEOUT_MILLIS), () -> {
        long pagesToGenerate = 142;
        DefaultPageCacheTracer tracer = new DefaultPageCacheTracer();
        getPageCache(fs, maxPages, tracer);
        long initialPins = tracer.pins();
        long initialUnpins = tracer.unpins();
        try (CursorContext cursorContext = new CursorContext(tracer.createPageCursorTracer("tracerMustBeNotifiedAboutPinUnpinFaultFlushAndEvictionEventsWhenWriting"));
            PagedFile pagedFile = map(file("a"), filePageSize);
            PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
            for (long i = 0; i < pagesToGenerate; i++) {
                assertTrue(cursor.next());
                assertThat(cursor.getCurrentPageId()).isEqualTo(i);
                // This does not count as a pin
                assertTrue(cursor.next(i));
                assertThat(cursor.getCurrentPageId()).isEqualTo(i);
                writeRecords(cursor);
            }
            // This counts as a single pin
            assertTrue(cursor.next(0));
            assertTrue(cursor.next(0));
        }
        assertThat(tracer.pins()).as("wrong count of pins").isEqualTo(pagesToGenerate + 1 + initialPins);
        assertThat(tracer.unpins()).as("wrong count of unpins").isEqualTo(pagesToGenerate + 1 + 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();
        assertThat(faults).as("wrong count of faults").isGreaterThanOrEqualTo(pagesToGenerate);
        // 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(pagesToGenerate - maxPages).isLessThanOrEqualTo(pagesToGenerate + faults);
        // We use greaterThanOrEqualTo because we visit each page twice, and
        // that leaves a small window wherein we can race with eviction, have
        // the evictor flush the page, and then fault it back and mark it as
        // dirty again.
        // We also subtract 'maxPages' from the expected flush count, because
        // vectored IO may coalesce all the flushes we do as part of unmapping
        // the file, into a single flush.
        long flushes = tracer.flushes();
        long bytesWritten = tracer.bytesWritten();
        assertThat(flushes).as("wrong count of flushes").isGreaterThanOrEqualTo(pagesToGenerate - maxPages);
        assertThat(bytesWritten).as("wrong count of bytes written").isGreaterThanOrEqualTo(pagesToGenerate * filePageSize);
    });
}
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)

Example 40 with DefaultPageCacheTracer

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

the class PageCacheTest method restartByShouldRetryMustCarryOverExistingPin.

@Test
void restartByShouldRetryMustCarryOverExistingPin() throws IOException {
    DefaultPageCacheTracer tracer = new DefaultPageCacheTracer();
    getPageCache(fs, 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);
                PageCursor writer = otherPagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
                while (!reader.shouldRetry()) {
                    for (int i = 0; i < maxPages * 10; i++) {
                        assertTrue(writer.next(i));
                    }
                }
            }
        }
    }
    // 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) 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