Search in sources :

Example 16 with IndexUpdater

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

the class NativeIndexProviderTest method shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor.

@Test
void shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() throws IOException, IndexEntryConflictException {
    // given
    Value someValue = Values.of(1);
    provider = newProvider();
    // when
    IndexDescriptor descriptor = descriptorUnique();
    try (IndexAccessor accessor = provider.getOnlineAccessor(descriptor, samplingConfig(), tokenNameLookup);
        IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        indexUpdater.process(IndexEntryUpdate.add(1, descriptor.schema(), someValue));
        // then
        // ... expect no failure on duplicate value
        indexUpdater.process(IndexEntryUpdate.add(2, descriptor.schema(), someValue));
    }
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) 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 17 with IndexUpdater

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

the class TokenIndexPopulatorTest method updaterShouldApplyUpdates.

@Test
void updaterShouldApplyUpdates() throws Exception {
    // Give
    MutableLongObjectMap<long[]> entityTokens = LongObjectMaps.mutable.empty();
    populator.create();
    List<TokenIndexEntryUpdate<?>> updates = TokenIndexUtility.generateSomeRandomUpdates(entityTokens, random);
    try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
        for (TokenIndexEntryUpdate<?> update : updates) {
            updater.process(update);
        }
    }
    // then
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    populator.close(true, NULL);
    TokenIndexUtility.verifyUpdates(entityTokens, layout, this::getTree);
}
Also used : TokenIndexEntryUpdate(org.neo4j.storageengine.api.TokenIndexEntryUpdate) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 18 with IndexUpdater

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

the class TokenIndexPopulatorTest method shouldHandleInterleavedRandomizedUpdates.

@Test
void shouldHandleInterleavedRandomizedUpdates() throws IndexEntryConflictException, IOException {
    // Give
    int numberOfEntities = 1_000;
    long currentScanId = 0;
    MutableLongObjectMap<long[]> entityTokens = LongObjectMaps.mutable.empty();
    populator.create();
    while (currentScanId < numberOfEntities) {
        // Collect a batch of max 100 updates from scan
        List<TokenIndexEntryUpdate<?>> updates = new ArrayList<>();
        for (int i = 0; i < 100 && currentScanId < numberOfEntities; i++) {
            TokenIndexUtility.generateRandomUpdate(currentScanId, entityTokens, updates, random);
            // Advance scan
            currentScanId++;
        }
        // Add updates to populator
        populator.add(updates, NULL);
        // Interleave external updates in id range lower than currentScanId
        try (IndexUpdater updater = populator.newPopulatingUpdater(NodePropertyAccessor.EMPTY, NULL)) {
            for (int i = 0; i < 100; i++) {
                long entityId = random.nextLong(currentScanId);
                // Current tokens for the entity in the tree
                long[] beforeTokens = entityTokens.get(entityId);
                if (beforeTokens == null) {
                    beforeTokens = EMPTY_LONG_ARRAY;
                }
                long[] afterTokens = TokenIndexUtility.generateRandomTokens(random);
                entityTokens.put(entityId, Arrays.copyOf(afterTokens, afterTokens.length));
                updater.process(IndexEntryUpdate.change(entityId, null, beforeTokens, afterTokens));
            }
        }
    }
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    populator.close(true, NULL);
    TokenIndexUtility.verifyUpdates(entityTokens, layout, this::getTree);
}
Also used : TokenIndexEntryUpdate(org.neo4j.storageengine.api.TokenIndexEntryUpdate) ArrayList(java.util.ArrayList) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 19 with IndexUpdater

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

the class FusionIndexUpdaterTest method initiateMocks.

private void initiateMocks() {
    IndexSlot[] activeSlots = fusionVersion.aliveSlots();
    updaters = new EnumMap<>(IndexSlot.class);
    fill(updaters, SwallowingIndexUpdater.INSTANCE);
    aliveUpdaters = new IndexUpdater[activeSlots.length];
    for (int i = 0; i < activeSlots.length; i++) {
        IndexUpdater mock = mock(IndexUpdater.class);
        aliveUpdaters[i] = mock;
        switch(activeSlots[i]) {
            case GENERIC:
                updaters.put(GENERIC, mock);
                break;
            case LUCENE:
                updaters.put(LUCENE, mock);
                break;
            default:
                throw new RuntimeException();
        }
    }
    fusionIndexUpdater = new FusionIndexUpdater(fusionVersion.slotSelector(), new LazyInstanceSelector<>(updaters, throwingFactory()));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) SwallowingIndexUpdater(org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)

Example 20 with IndexUpdater

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

the class FusionIndexUpdaterTest method closeMustCloseOthersIfAnyThrow.

@Test
void closeMustCloseOthersIfAnyThrow() throws Exception {
    for (IndexSlot indexSlot : fusionVersion.aliveSlots()) {
        IndexUpdater failingUpdater = updaters.get(indexSlot);
        FusionIndexTestHelp.verifyOtherIsClosedOnSingleThrow(failingUpdater, fusionIndexUpdater, without(aliveUpdaters, failingUpdater));
        initiateMocks();
    }
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) SwallowingIndexUpdater(org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater) 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