Search in sources :

Example 81 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext 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 82 with CursorContext

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

the class MuninnPageCacheTest method pageModificationTrackingNoticeWriteFromAnotherThread.

@Test
void pageModificationTrackingNoticeWriteFromAnotherThread() throws Exception {
    TestVersionContext versionContext = new TestVersionContext(() -> 0);
    CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext);
    try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
        PagedFile pagedFile = map(pageCache, file("a"), 8)) {
        versionContext.initWrite(7);
        Future<?> future = executor.submit(() -> {
            try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
                assertTrue(cursor.next());
                cursor.putLong(1);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        future.get();
        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) IOException(java.io.IOException) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 83 with CursorContext

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

the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingFirstPage.

@Test
void mustFlushDirtyPagesOnEvictingFirstPage() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorContext = new RecordingPageCursorTracer(tracer, "mustFlushDirtyPagesOnEvictingFirstPage");
    try (MuninnPageCache pageCache = createPageCache(fs, 2, blockCacheFlush(tracer));
        PagedFile pagedFile = map(pageCache, file("a"), 8)) {
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, new CursorContext(cursorContext))) {
            assertTrue(cursor.next());
            cursor.putLong(0L);
        }
        cursorContext.reportEvents();
        assertNotNull(cursorContext.observe(Fault.class));
        assertEquals(1, cursorContext.faults());
        assertEquals(1, tracer.faults());
        long clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
        assertThat(clockArm).isEqualTo(1L);
        assertNotNull(tracer.observe(Evict.class));
        ByteBuffer buf = readIntoBuffer("a");
        assertThat(buf.getLong()).isEqualTo(0L);
        assertThat(buf.getLong()).isEqualTo(y);
    }
}
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 84 with CursorContext

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

the class MuninnPageCacheTest method mustEvictCleanPageWithoutFlushing.

@Test
void mustEvictCleanPageWithoutFlushing() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorContext = new RecordingPageCursorTracer(tracer, "mustEvictCleanPageWithoutFlushing");
    try (MuninnPageCache pageCache = createPageCache(fs, 2, blockCacheFlush(tracer));
        PagedFile pagedFile = map(pageCache, file("a"), 8)) {
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, new CursorContext(cursorContext))) {
            assertTrue(cursor.next());
        }
        cursorContext.reportEvents();
        assertNotNull(cursorContext.observe(Fault.class));
        assertEquals(1, cursorContext.faults());
        assertEquals(1, tracer.faults());
        long clockArm = pageCache.evictPages(1, 1, tracer.beginPageEvictions(1));
        assertThat(clockArm).isEqualTo(1L);
        assertNotNull(tracer.observe(Evict.class));
    }
}
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) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.jupiter.api.Test)

Example 85 with CursorContext

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

the class MuninnPageCacheTest method markCursorContextDirtyWhenRepositionCursorOnItsCurrentPage.

@Test
void markCursorContextDirtyWhenRepositionCursorOnItsCurrentPage() throws IOException {
    TestVersionContext versionContext = new TestVersionContext(() -> 3);
    CursorContext cursorContext = new CursorContext(PageCursorTracer.NULL, versionContext);
    try (MuninnPageCache pageCache = createPageCache(fs, 2, PageCacheTracer.NULL);
        PagedFile pagedFile = map(pageCache, file("a"), 8)) {
        versionContext.initRead();
        try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, cursorContext)) {
            assertTrue(cursor.next(0));
            assertFalse(versionContext.isDirty());
            MuninnPageCursor pageCursor = (MuninnPageCursor) cursor;
            pageCursor.pagedFile.setLastModifiedTxId(((MuninnPageCursor) cursor).pinnedPageRef, 17);
            assertTrue(cursor.next(0));
            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)

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