Search in sources :

Example 91 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class MuninnPageCacheTest method mustEvictCleanPageWithoutFlushing.

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

Example 92 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class RecordStresser method call.

@Override
public Void call() throws Exception {
    Random random = new Random();
    int recordsPerPage = format.getRecordsPerPage();
    int recordSize = format.getRecordSize();
    try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
        while (!condition.fulfilled()) {
            int recordId = random.nextInt(maxRecords);
            int pageId = recordId / recordsPerPage;
            int recordOffset = (recordId % recordsPerPage) * recordSize;
            locks.lock(recordId);
            try {
                assertTrue("I must be able to access pages", cursor.next(pageId));
                cursor.setOffset(recordOffset);
                long newValue = format.incrementCounter(cursor, threadId);
                countSum++;
                assertFalse("Write lock, so never a need to retry", cursor.shouldRetry());
                assertThat("Record-local count must be less than or equal to thread-local count sum", newValue, lessThanOrEqualTo(countSum));
            } finally {
                locks.unlock(recordId);
            }
        }
    }
    return null;
}
Also used : Random(java.util.Random) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 93 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class RecordStresser method verifyCounts.

public void verifyCounts() throws IOException {
    long actualSum = 0;
    try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK)) {
        while (cursor.next()) {
            actualSum += format.sumCountsForThread(cursor, threadId);
        }
    }
    assertThat("Thread specific sum across all records", actualSum, is(countSum));
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 94 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class MuninnPageCacheTest method mustFlushDirtyPagesOnEvictingLastPage.

@Test
public void mustFlushDirtyPagesOnEvictingLastPage() throws Exception {
    writeInitialDataTo(file("a"));
    RecordingPageCacheTracer tracer = new RecordingPageCacheTracer();
    RecordingPageCursorTracer cursorTracer = new RecordingPageCursorTracer();
    ConfigurablePageCursorTracerSupplier cursorTracerSupplier = new ConfigurablePageCursorTracerSupplier(cursorTracer);
    MuninnPageCache pageCache = createPageCache(fs, 2, 8, blockCacheFlush(tracer), cursorTracerSupplier);
    PagedFile pagedFile = pageCache.map(file("a"), 8);
    try (PageCursor cursor = pagedFile.io(1, PF_SHARED_WRITE_LOCK)) {
        assertTrue(cursor.next());
        cursor.putLong(0L);
    }
    cursorTracer.reportEvents();
    assertNotNull(cursorTracer.observe(Fault.class));
    assertEquals(1, cursorTracer.faults());
    assertEquals(1, tracer.faults());
    int clockArm = pageCache.evictPages(1, 0, tracer.beginPageEvictions(1));
    assertThat(clockArm, is(1));
    assertNotNull(tracer.observe(Evict.class));
    ByteBuffer buf = ByteBuffer.allocate(16);
    StoreChannel channel = fs.open(file("a"), "r");
    channel.read(buf);
    buf.flip();
    assertThat(buf.getLong(), is(x));
    assertThat(buf.getLong(), is(0L));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) 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) RecordingPageCursorTracer(org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer) ByteBuffer(java.nio.ByteBuffer) ConfigurablePageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier) PageCursor(org.neo4j.io.pagecache.PageCursor) PageCacheTest(org.neo4j.io.pagecache.PageCacheTest) Test(org.junit.Test)

Example 95 with PageCursor

use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.

the class CompositePageCursorTest method getLongWithOffsetMustHitCorrectCursors.

@Test
public void getLongWithOffsetMustHitCorrectCursors() throws Exception {
    first.setOffset(1);
    second.setOffset(2);
    PageCursor c = CompositePageCursor.compose(first, 1 + 8, second, 8);
    assertThat(c.getLong(1), is(0xA2A3A4A5A6A7A8A9L));
    assertThat(c.getLong(1 + 8), is(0xB2B3B4B5B6B7B8B9L));
    assertFalse(c.checkAndClearBoundsFlag());
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor) StubPageCursor(org.neo4j.io.pagecache.StubPageCursor) Test(org.junit.Test)

Aggregations

PageCursor (org.neo4j.io.pagecache.PageCursor)184 Test (org.junit.Test)124 StubPageCursor (org.neo4j.io.pagecache.StubPageCursor)106 PagedFile (org.neo4j.io.pagecache.PagedFile)19 IOException (java.io.IOException)12 File (java.io.File)8 CursorException (org.neo4j.io.pagecache.CursorException)6 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)6 CompositePageCursor (org.neo4j.io.pagecache.impl.CompositePageCursor)6 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)6 ByteBuffer (java.nio.ByteBuffer)5 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)5 StoreChannel (org.neo4j.io.fs.StoreChannel)4 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)4 ConfigurablePageCursorTracerSupplier (org.neo4j.io.pagecache.tracing.ConfigurablePageCursorTracerSupplier)4 RecordingPageCacheTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer)4 Evict (org.neo4j.io.pagecache.tracing.recording.RecordingPageCacheTracer.Evict)4 RecordingPageCursorTracer (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer)4 Fault (org.neo4j.io.pagecache.tracing.recording.RecordingPageCursorTracer.Fault)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3