use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class StoreUpgraderTest method tracePageCacheAccessOnStoreUpgrade.
@ParameterizedTest
@MethodSource("versions")
void tracePageCacheAccessOnStoreUpgrade(RecordFormats formats) throws IOException {
init(formats);
fileSystem.deleteFile(databaseLayout.file(INTERNAL_LOG_FILE));
StoreVersionCheck check = getVersionCheck(pageCache);
var pageCacheTracer = new DefaultPageCacheTracer();
newUpgrader(check, allowMigrateConfig, pageCache, pageCacheTracer).migrateIfNeeded(databaseLayout, false);
assertThat(pageCacheTracer.hits()).isGreaterThan(0);
assertThat(pageCacheTracer.pins()).isGreaterThan(0);
assertThat(pageCacheTracer.unpins()).isGreaterThan(0);
assertThat(pageCacheTracer.faults()).isGreaterThan(0);
StoreFactory factory = new StoreFactory(databaseLayout, allowMigrateConfig, new ScanOnOpenOverwritingIdGeneratorFactory(fileSystem, databaseLayout.getDatabaseName()), pageCache, fileSystem, NullLogProvider.getInstance(), NULL, writable());
try (NeoStores neoStores = factory.openAllNeoStores()) {
assertThat(neoStores.getMetaDataStore().getUpgradeTransaction()).isEqualTo(neoStores.getMetaDataStore().getLastCommittedTransaction());
assertThat(neoStores.getMetaDataStore().getUpgradeTime()).isPositive();
}
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class FullScanNonUniqueIndexSamplerTest method tracePageCacheAccessOnSampling.
@Test
void tracePageCacheAccessOnSampling() throws IOException {
Value[] values = generateNumberValues();
buildTree(values);
var pageCacheTracer = new DefaultPageCacheTracer();
var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("testTracer"));
assertZeroCursor(cursorContext);
try (GBPTree<GenericKey, NativeIndexValue> gbpTree = getTree()) {
FullScanNonUniqueIndexSampler<GenericKey, NativeIndexValue> sampler = new FullScanNonUniqueIndexSampler<>(gbpTree, layout);
sampler.sample(cursorContext);
}
PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
assertThat(cursorTracer.pins()).isEqualTo(1);
assertThat(cursorTracer.unpins()).isEqualTo(1);
assertThat(cursorTracer.faults()).isEqualTo(1);
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class IndexStatisticsStoreTest method tracePageCacheAccessOnCheckpoint.
@Test
void tracePageCacheAccessOnCheckpoint() throws IOException {
var cacheTracer = new DefaultPageCacheTracer();
var store = openStore(cacheTracer, "checkpoint");
try (var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnCheckpoint"))) {
for (int i = 0; i < 100; i++) {
store.replaceStats(i, new IndexSample());
}
store.checkpoint(cursorContext);
PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
assertThat(cursorTracer.pins()).isEqualTo(43);
assertThat(cursorTracer.unpins()).isEqualTo(43);
assertThat(cursorTracer.hits()).isEqualTo(35);
assertThat(cursorTracer.faults()).isEqualTo(8);
}
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class IndexStatisticsStoreTest method tracePageCacheAccessOnConsistencyCheck.
@Test
void tracePageCacheAccessOnConsistencyCheck() throws IOException {
var cacheTracer = new DefaultPageCacheTracer();
var store = openStore(cacheTracer, "consistencyCheck");
try (var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnConsistencyCheck"))) {
for (int i = 0; i < 100; i++) {
store.replaceStats(i, new IndexSample());
}
store.checkpoint(CursorContext.NULL);
store.consistencyCheck(noopReporterFactory(), cursorContext);
PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
assertThat(cursorTracer.pins()).isEqualTo(16);
assertThat(cursorTracer.unpins()).isEqualTo(16);
assertThat(cursorTracer.hits()).isEqualTo(16);
}
}
use of org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer in project neo4j by neo4j.
the class PageCacheTest method tracerMustBeNotifiedAboutPinUnpinFaultAndEvictEventsWhenReading.
@Test
void tracerMustBeNotifiedAboutPinUnpinFaultAndEvictEventsWhenReading() {
assertTimeoutPreemptively(ofMillis(SHORT_TIMEOUT_MILLIS), () -> {
DefaultPageCacheTracer tracer = new DefaultPageCacheTracer();
getPageCache(fs, maxPages, tracer);
generateFileWithRecords(file("a"), recordCount, recordSize);
long initialPins = tracer.pins();
long initialUnpins = tracer.unpins();
long countedPages = 0;
long countedFaults = 0;
try (CursorContext cursorContext = new CursorContext(tracer.createPageCursorTracer("tracerMustBeNotifiedAboutPinUnpinFaultAndEvictEventsWhenReading"));
PagedFile pagedFile = map(file("a"), filePageSize);
PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
while (cursor.next()) {
countedPages++;
countedFaults++;
}
// Using next( pageId ) to the already-pinned page id does not count,
// so we only increment once for this section
countedPages++;
for (int i = 0; i < 20; i++) {
assertTrue(cursor.next(1));
}
// then it counts
for (int i = 0; i < 20; i++) {
assertTrue(cursor.next(i));
countedPages++;
}
}
assertThat(tracer.pins()).as("wrong count of pins").isEqualTo(countedPages + initialPins);
assertThat(tracer.unpins()).as("wrong count of unpins").isEqualTo(countedPages + 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();
long bytesRead = tracer.bytesRead();
assertThat(faults).as("wrong count of faults").isGreaterThanOrEqualTo(countedFaults);
assertThat(bytesRead).as("wrong number of bytes read").isGreaterThanOrEqualTo(countedFaults * filePageSize);
// 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(countedFaults - maxPages).isLessThanOrEqualTo(countedPages + faults);
});
}
Aggregations