Search in sources :

Example 51 with IndexSample

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

the class FusionIndexSampler method combineSamples.

public static IndexSample combineSamples(Iterable<IndexSample> samples) {
    long indexSize = 0;
    long uniqueValues = 0;
    long sampleSize = 0;
    for (IndexSample sample : samples) {
        indexSize += sample.indexSize();
        uniqueValues += sample.uniqueValues();
        sampleSize += sample.sampleSize();
    }
    return new IndexSample(indexSize, uniqueValues, sampleSize);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample)

Example 52 with IndexSample

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

the class BlockBasedIndexPopulatorTest method shouldBuildNonUniqueSampleAsPartOfScanCompleted.

@Test
void shouldBuildNonUniqueSampleAsPartOfScanCompleted() throws IndexEntryConflictException, IOException {
    // given
    ThreadSafePeakMemoryTracker memoryTracker = new ThreadSafePeakMemoryTracker();
    ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, 100);
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, memoryTracker);
    Collection<IndexEntryUpdate<?>> populationUpdates = batchOfUpdates();
    populator.add(populationUpdates, NULL);
    // when
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    // Also a couple of updates afterwards
    int numberOfUpdatesAfterCompleted = 4;
    try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
        for (int i = 0; i < numberOfUpdatesAfterCompleted; i++) {
            updater.process(IndexEntryUpdate.add(10_000 + i, SCHEMA_DESCRIPTOR, intValue(i)));
        }
    }
    populator.close(true, NULL);
    // then
    IndexSample sample = populator.sample(NULL);
    assertEquals(populationUpdates.size(), sample.indexSize());
    assertEquals(populationUpdates.size(), sample.sampleSize());
    assertEquals(populationUpdates.size(), sample.uniqueValues());
    assertEquals(numberOfUpdatesAfterCompleted, sample.updates());
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexSample(org.neo4j.kernel.api.index.IndexSample) ThreadSafePeakMemoryTracker(org.neo4j.memory.ThreadSafePeakMemoryTracker) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ByteBufferFactory(org.neo4j.io.memory.ByteBufferFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with IndexSample

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

the class BlockBasedIndexPopulatorTest method shouldCountExternalUpdatesAsSampleUpdates.

@Test
void shouldCountExternalUpdatesAsSampleUpdates() throws IOException, IndexEntryConflictException {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR);
    try {
        populator.add(List.of(add(0), add(1)), NULL);
        try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
            updater.process(add(10));
            updater.process(add(11));
            updater.process(add(12));
        }
        // when
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
            updater.process(remove(10));
        }
        // then
        IndexSample sample = populator.sample(NULL);
        assertThat(sample.updates()).isEqualTo(4);
    } finally {
        populator.close(true, NULL);
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with IndexSample

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

the class FullScanNonUniqueIndexSamplerTest method shouldIncludeAllValuesInTree.

@Test
void shouldIncludeAllValuesInTree() throws Exception {
    // GIVEN
    Value[] values = generateNumberValues();
    buildTree(values);
    // WHEN
    IndexSample sample;
    try (GBPTree<GenericKey, NativeIndexValue> gbpTree = getTree()) {
        FullScanNonUniqueIndexSampler<GenericKey, NativeIndexValue> sampler = new FullScanNonUniqueIndexSampler<>(gbpTree, layout);
        sample = sampler.sample(NULL);
    }
    // THEN
    assertEquals(values.length, sample.sampleSize());
    assertEquals(countUniqueValues(values), sample.uniqueValues());
    assertEquals(values.length, sample.indexSize());
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Value(org.neo4j.values.storable.Value) NumberValue(org.neo4j.values.storable.NumberValue) Test(org.junit.jupiter.api.Test)

Example 55 with IndexSample

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

the class OnlineIndexSamplingJob method run.

@Override
public void run() {
    try (DurationLogger durationLogger = new DurationLogger(log, "Sampling index " + indexUserDescription)) {
        try {
            try (var reader = indexProxy.newValueReader();
                var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(INDEX_SAMPLER_TAG));
                IndexSampler sampler = reader.createSampler()) {
                IndexSample sample = sampler.sampleIndex(cursorContext);
                // check again if the index is online before saving the counts in the store
                if (indexProxy.getState() == ONLINE) {
                    indexStatisticsStore.replaceStats(indexId, sample);
                    durationLogger.markAsFinished();
                    log.debug(format("Sampled index %s with %d unique values in sample of avg size %d taken from " + "index containing %d entries", indexUserDescription, sample.uniqueValues(), sample.sampleSize(), sample.indexSize()));
                } else {
                    durationLogger.markAsAborted("Index no longer ONLINE");
                }
            }
        } catch (IndexNotFoundKernelException e) {
            durationLogger.markAsAborted("Attempted to sample missing/already deleted index " + indexUserDescription);
        }
    }
}
Also used : DurationLogger(org.neo4j.kernel.impl.util.DurationLogger) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexSampler(org.neo4j.kernel.api.index.IndexSampler)

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