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));
}
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;
}
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));
}
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));
}
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());
}
Aggregations