Search in sources :

Example 51 with CursorContext

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

the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingAllPages.

@Test
void mustFlushDirtyPagesOnEvictingAllPages() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorContext = new RecordingPageCursorTracer(tracer, "mustFlushDirtyPagesOnEvictingAllPages", Fault.class);
    try (MuninnPageCache pageCache = createPageCache(fs, 4, blockCacheFlush(tracer));
        PagedFile pagedFile = map(pageCache, file("a"), 8)) {
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK | PF_NO_GROW, new CursorContext(cursorContext))) {
            assertTrue(cursor.next());
            cursor.putLong(0L);
            assertTrue(cursor.next());
            cursor.putLong(0L);
            assertFalse(cursor.next());
        }
        cursorContext.reportEvents();
        assertNotNull(cursorContext.observe(Fault.class));
        assertNotNull(cursorContext.observe(Fault.class));
        assertEquals(2, cursorContext.faults());
        assertEquals(2, tracer.faults());
        long clockArm = pageCache.evictPages(2, 0, tracer.beginPageEvictions(2));
        assertThat(clockArm).isEqualTo(2L);
        assertNotNull(tracer.observe(Evict.class));
        assertNotNull(tracer.observe(Evict.class));
        ByteBuffer buf = readIntoBuffer("a");
        assertThat(buf.getLong()).isEqualTo(0L);
        assertThat(buf.getLong()).isEqualTo(0L);
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) RecordingPageCacheTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer) Fault(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault) Evict(org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 52 with CursorContext

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

the class MuninnPageCacheTest method trackPageModificationTransactionId.

@Test
void trackPageModificationTransactionId() throws Exception {
    TestVersionContext versionContext = new TestVersionContext(() -> 0);
    try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
        PagedFile pagedFile = map(pageCache, file("a"), 8);
        CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext)) {
        versionContext.initWrite(7);
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
            assertTrue(cursor.next());
            cursor.putLong(1);
        }
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
            assertTrue(cursor.next());
            MuninnPageCursor pageCursor = (MuninnPageCursor) cursor;
            assertEquals(7, pageCursor.pagedFile.getLastModifiedTxId(pageCursor.pinnedPageRef));
            assertEquals(1, cursor.getLong());
        }
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 53 with CursorContext

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

the class MuninnPageCacheTest method markContextAsDirtyWhenAnyEvictedPageHaveModificationTransactionHigherThenReader.

@Test
void markContextAsDirtyWhenAnyEvictedPageHaveModificationTransactionHigherThenReader() throws IOException {
    TestVersionContext versionContext = new TestVersionContext(() -> 5);
    try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
        PagedFile pagedFile = map(pageCache, file("a"), 8);
        CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext)) {
        versionContext.initWrite(3);
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
            assertTrue(cursor.next());
            cursor.putLong(3);
        }
        versionContext.initWrite(13);
        try (PageCursor cursor = pagedFile.io(1, PF_SHARED_WRITE_LOCK, cursorContext)) {
            assertTrue(cursor.next());
            cursor.putLong(4);
        }
        evictAllPages(pageCache);
        versionContext.initRead();
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
            assertTrue(cursor.next());
            assertEquals(3, cursor.getLong());
            assertTrue(versionContext.isDirty());
        }
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 54 with CursorContext

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

the class MuninnPageCacheTest method shouldBeAbleToSetDeleteOnCloseFileAfterItWasMapped.

@Test
void shouldBeAbleToSetDeleteOnCloseFileAfterItWasMapped() throws IOException {
    DefaultPageCacheTracer defaultPageCacheTracer = new DefaultPageCacheTracer();
    Path fileForDeletion = file("fileForDeletion");
    writeInitialDataTo(fileForDeletion);
    long initialFlushes = defaultPageCacheTracer.flushes();
    try (MuninnPageCache pageCache = createPageCache(fs, 2, defaultPageCacheTracer)) {
        try (var cursorContext = new CursorContext(defaultPageCacheTracer.createPageCursorTracer("shouldBeAbleToSetDeleteOnCloseFileAfterItWasMapped"));
            PagedFile pagedFile = map(pageCache, fileForDeletion, 8)) {
            try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
                assertTrue(cursor.next());
                cursor.putLong(0L);
            }
            pagedFile.setDeleteOnClose(true);
        }
        assertFalse(fs.fileExists(fileForDeletion));
        assertEquals(0, defaultPageCacheTracer.flushes() - initialFlushes);
    }
}
Also used : Path(java.nio.file.Path) PagedFile(org.neo4j.io.pagecache.PagedFile) CursorContext(org.neo4j.io.pagecache.context.CursorContext) 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 55 with CursorContext

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

the class MuninnPageCacheTest method reportFreeListSizeToTracers.

@Test
void reportFreeListSizeToTracers() throws IOException {
    var pageCacheTracer = new InfoTracer();
    try (MuninnPageCache pageCache = createPageCache(fs, 10, pageCacheTracer);
        PagedFile pagedFile = map(pageCache, file("a"), (int) ByteUnit.kibiBytes(8))) {
        for (int pageId = 0; pageId < 5; pageId++) {
            CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("test"));
            try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK, cursorContext)) {
                assertTrue(cursor.next());
                cursor.putLong(1);
            }
            assertEquals(10 - (pageId + 1), pageCacheTracer.getFreeListSize());
        }
        pagedFile.flushAndForce();
    }
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) 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