Search in sources :

Example 11 with IndexUpdater

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

the class NativeIndexPopulatorTests method updaterMustThrowIfProcessAfterClose.

@Test
void updaterMustThrowIfProcessAfterClose() throws Exception {
    // given
    populator.create();
    IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
    // when
    updater.close();
    assertThrows(IllegalStateException.class, () -> updater.process(valueCreatorUtil.add(1, Values.of(Long.MAX_VALUE))));
    populator.close(true, NULL);
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 12 with IndexUpdater

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

the class NativeIndexPopulatorTests method interleaveLargeAmountOfUpdates.

int interleaveLargeAmountOfUpdates(Random updaterRandom, Iterator<? extends IndexEntryUpdate<IndexDescriptor>> updates) throws IndexEntryConflictException {
    int count = 0;
    for (int i = 0; i < LARGE_AMOUNT_OF_UPDATES; i++) {
        if (updaterRandom.nextFloat() < 0.1) {
            try (IndexUpdater indexUpdater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
                int numberOfUpdaterUpdates = updaterRandom.nextInt(100);
                for (int j = 0; j < numberOfUpdaterUpdates; j++) {
                    indexUpdater.process(updates.next());
                    count++;
                }
            }
        }
        populator.add(Collections.singletonList(updates.next()), NULL);
        count++;
    }
    return count;
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 13 with IndexUpdater

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

the class NativeIndexPopulatorTests method applyInterleaved.

void applyInterleaved(IndexEntryUpdate<IndexDescriptor>[] updates, IndexPopulator populator) throws IndexEntryConflictException {
    boolean useUpdater = true;
    Collection<IndexEntryUpdate<IndexDescriptor>> populatorBatch = new ArrayList<>();
    IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
    for (IndexEntryUpdate<IndexDescriptor> update : updates) {
        if (random.nextInt(100) < 20) {
            if (useUpdater) {
                updater.close();
                populatorBatch = new ArrayList<>();
            } else {
                populator.add(populatorBatch, NULL);
                updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
            }
            useUpdater = !useUpdater;
        }
        if (useUpdater) {
            updater.process(update);
        } else {
            populatorBatch.add(update);
        }
    }
    if (useUpdater) {
        updater.close();
    } else {
        populator.add(populatorBatch, NULL);
    }
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 14 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater 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 15 with IndexUpdater

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

the class NativeNonUniqueIndexPopulatorTest method updaterShouldApplyDuplicateValues.

@Test
void updaterShouldApplyDuplicateValues() throws Exception {
    // given
    populator.create();
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = valueCreatorUtil.someUpdatesWithDuplicateValues(random);
    try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
        // when
        for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
            updater.process(update);
        }
    }
    // then
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    populator.close(true, NULL);
    valueUtil.verifyUpdates(updates, this::getTree);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Aggregations

IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)94 Test (org.junit.jupiter.api.Test)61 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)13 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)9 Value (org.neo4j.values.storable.Value)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)7 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)6 SwallowingIndexUpdater (org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)4 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)4 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)4 HashMap (java.util.HashMap)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3