Search in sources :

Example 6 with IndexSample

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

the class IndexSamplingControllerFactory method createIndexRecoveryCondition.

private RecoveryCondition createIndexRecoveryCondition(final LogProvider logProvider, final TokenNameLookup tokenNameLookup) {
    return new RecoveryCondition() {

        private final Log log = logProvider.getLog(IndexSamplingController.class);

        @Override
        public boolean test(IndexDescriptor descriptor) {
            IndexSample indexSample = indexStatisticsStore.indexSample(descriptor.getId());
            long samples = indexSample.sampleSize();
            long size = indexSample.indexSize();
            boolean empty = (samples == 0) || (size == 0);
            if (empty) {
                log.debug("Recovering index sampling for index %s", descriptor.schema().userDescription(tokenNameLookup));
            }
            return empty;
        }
    };
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Log(org.neo4j.logging.Log) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 7 with IndexSample

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

the class NativeIndexAccessorTests method shouldSampleIndex.

@Test
void shouldSampleIndex() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
    processAll(updates);
    try (var reader = accessor.newValueReader();
        IndexSampler sampler = reader.createSampler()) {
        // when
        IndexSample sample = sampler.sampleIndex(NULL);
        // then
        assertEquals(updates.length, sample.indexSize());
        assertEquals(updates.length, sample.sampleSize());
        assertEquals(countUniqueValues(updates), sample.uniqueValues());
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) Test(org.junit.jupiter.api.Test)

Example 8 with IndexSample

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

the class FusionIndexProviderTest method mustCombineSamples.

@Test
void mustCombineSamples() {
    // given
    int sumIndexSize = 0;
    int sumUniqueValues = 0;
    int sumSampleSize = 0;
    IndexSample[] samples = new IndexSample[providers.size()];
    for (int i = 0; i < samples.length; i++) {
        int indexSize = random.nextInt(0, 1_000_000);
        int uniqueValues = random.nextInt(0, 1_000_000);
        int sampleSize = random.nextInt(0, 1_000_000);
        samples[i] = new IndexSample(indexSize, uniqueValues, sampleSize);
        sumIndexSize += indexSize;
        sumUniqueValues += uniqueValues;
        sumSampleSize += sampleSize;
    }
    // when
    IndexSample fusionSample = FusionIndexSampler.combineSamples(Arrays.asList(samples));
    // then
    assertEquals(sumIndexSize, fusionSample.indexSize());
    assertEquals(sumUniqueValues, fusionSample.uniqueValues());
    assertEquals(sumSampleSize, fusionSample.sampleSize());
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 9 with IndexSample

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

the class NativeNonUniqueIndexPopulatorTest method shouldSampleUpdatesIfConfiguredForOnlineSampling.

@Test
void shouldSampleUpdatesIfConfiguredForOnlineSampling() throws Exception {
    // GIVEN
    try {
        populator.create();
        ValueIndexEntryUpdate<IndexDescriptor>[] scanUpdates = valueCreatorUtil.someUpdates(random);
        populator.add(asList(scanUpdates), NULL);
        Iterator<ValueIndexEntryUpdate<IndexDescriptor>> generator = valueCreatorUtil.randomUpdateGenerator(random);
        Value[] updates = new Value[5];
        updates[0] = generator.next().values()[0];
        updates[1] = generator.next().values()[0];
        updates[2] = updates[1];
        updates[3] = generator.next().values()[0];
        updates[4] = updates[3];
        try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
            long nodeId = 1000;
            for (Value value : updates) {
                ValueIndexEntryUpdate<IndexDescriptor> update = valueCreatorUtil.add(nodeId++, value);
                updater.process(update);
            }
        }
        // WHEN
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        IndexSample sample = populator.sample(NULL);
        // THEN
        assertEquals(scanUpdates.length, sample.sampleSize());
        assertEquals(countUniqueValues(scanUpdates), sample.uniqueValues());
        assertEquals(scanUpdates.length, sample.indexSize());
        assertEquals(updates.length, sample.updates());
    } finally {
        populator.close(true, NULL);
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 10 with IndexSample

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

the class NonUniqueLuceneIndexPopulatingUpdaterIT method shouldSampleUpdates.

@Test
void shouldSampleUpdates() throws Exception {
    // Given
    var provider = createIndexProvider();
    var populator = getPopulator(provider, SCHEMA_DESCRIPTOR);
    // When
    try (var updater = populator.newPopulatingUpdater(mock(NodePropertyAccessor.class), NULL)) {
        updater.process(add(1, SCHEMA_DESCRIPTOR, "initial1"));
        updater.process(add(2, SCHEMA_DESCRIPTOR, "initial2"));
        updater.process(add(3, SCHEMA_DESCRIPTOR, "new2"));
        updater.process(change(1, SCHEMA_DESCRIPTOR, "initial1", "new1"));
        updater.process(change(1, SCHEMA_DESCRIPTOR, "initial2", "new2"));
    }
    // Then samples calculated with documents pending merge
    assertThat(populator.sample(NULL)).isEqualTo(new IndexSample(3, 4, 5));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) 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