Search in sources :

Example 1 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class FusionIndexIT method verifyContent.

private void verifyContent() {
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(30, TimeUnit.SECONDS);
        assertEquals(1L, Iterators.stream(tx.schema().getIndexes(label).iterator()).count());
        assertNotNull(tx.findNode(label, propKey, numberValue));
        assertNotNull(tx.findNode(label, propKey, stringValue));
        assertNotNull(tx.findNode(label, propKey, spatialValue));
        assertNotNull(tx.findNode(label, propKey, temporalValue));
        assertThat(indexSample()).isEqualTo(new IndexSample(4, 4, 4, 0));
        tx.commit();
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Transaction(org.neo4j.graphdb.Transaction)

Example 2 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample 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);
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 3 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class IndexStatisticsStoreTest method shouldHandleConcurrentUpdatesWithCheckpointing.

@Test
void shouldHandleConcurrentUpdatesWithCheckpointing() throws Throwable {
    // given
    Race race = new Race();
    AtomicBoolean checkpointDone = new AtomicBoolean();
    int contestantsPerIndex = 5;
    int indexes = 3;
    int delta = 5;
    AtomicIntegerArray expected = new AtomicIntegerArray(indexes);
    race.addContestant(throwing(() -> {
        for (int i = 0; i < 20; i++) {
            Thread.sleep(5);
            store.checkpoint(CursorContext.NULL);
        }
        checkpointDone.set(true);
    }));
    for (int i = 0; i < indexes; i++) {
        int indexId = i;
        store.replaceStats(indexId, new IndexSample(0, 0, 0));
        race.addContestants(contestantsPerIndex, () -> {
            while (!checkpointDone.get()) {
                store.incrementIndexUpdates(indexId, delta);
                expected.addAndGet(indexId, delta);
            }
        });
    }
    // when
    race.go();
    // then
    for (int i = 0; i < indexes; i++) {
        assertEquals(new IndexSample(0, 0, 0, expected.get(i)), store.indexSample(i));
    }
    restartStore();
    for (int i = 0; i < indexes; i++) {
        assertEquals(new IndexSample(0, 0, 0, expected.get(i)), store.indexSample(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexSample(org.neo4j.kernel.api.index.IndexSample) Race(org.neo4j.test.Race) Test(org.junit.jupiter.api.Test)

Example 4 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample 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);
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 5 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class BlockEntryStreamMergerTest method shouldMergePartsIntoOneWithSampling.

@Test
void shouldMergePartsIntoOneWithSampling() throws Exception {
    // given
    List<BlockEntryCursor<RawBytes, RawBytes>> parts = buildParts(random, layout, allData);
    // when
    try (BlockEntryStreamMerger<RawBytes, RawBytes> merger = new BlockEntryStreamMerger<>(parts, layout, layout, NOT_CANCELLABLE, BATCH_SIZE, QUEUE_SIZE)) {
        Future<Void> t2Future = t2.execute(merger);
        // then
        assertMergedPartStream(allData, merger);
        t2Future.get();
        IndexSample sample = merger.buildIndexSample();
        assertThat(sample.sampleSize()).isEqualTo(allData.size());
        assertThat(sample.indexSize()).isEqualTo(allData.size());
        assertThat(sample.uniqueValues()).isEqualTo(countUniqueKeys(allData));
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) RawBytes(org.neo4j.index.internal.gbptree.RawBytes) Test(org.junit.jupiter.api.Test)

Aggregations

IndexSample (org.neo4j.kernel.api.index.IndexSample)56 Test (org.junit.jupiter.api.Test)43 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)14 CursorContext (org.neo4j.io.pagecache.context.CursorContext)13 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)8 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)8 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)8 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)7 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)7 ArrayList (java.util.ArrayList)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Config (org.neo4j.configuration.Config)6 Transaction (org.neo4j.graphdb.Transaction)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 Arrays.asList (java.util.Arrays.asList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4