Search in sources :

Example 86 with IndexUpdater

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

the class NativeIndexAccessorTests method shouldHandleMultipleConsecutiveUpdaters.

@Test
void shouldHandleMultipleConsecutiveUpdaters() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
    // when
    for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
        try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
            updater.process(update);
        }
    }
    // then
    forceAndCloseAccessor();
    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)

Example 87 with IndexUpdater

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

the class IndexUpdaterMap method getUpdater.

IndexUpdater getUpdater(IndexDescriptor descriptor, CursorContext cursorContext) {
    IndexUpdater updater = updaterMap.get(descriptor);
    if (null == updater) {
        IndexProxy indexProxy = indexMap.getIndexProxy(descriptor);
        if (null != indexProxy) {
            updater = indexProxy.newUpdater(indexUpdateMode, cursorContext);
            updaterMap.put(descriptor, updater);
        }
    }
    return updater;
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 88 with IndexUpdater

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

the class TokenIndexAccessorTest method shouldAddWithUpdater.

@Test
void shouldAddWithUpdater() throws IndexEntryConflictException, IOException {
    // Give
    MutableLongObjectMap<long[]> entityTokens = LongObjectMaps.mutable.empty();
    List<TokenIndexEntryUpdate<?>> updates = generateSomeRandomUpdates(entityTokens, random);
    // When
    try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
        for (TokenIndexEntryUpdate<?> update : updates) {
            updater.process(update);
        }
    }
    // Then
    forceAndCloseAccessor();
    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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with IndexUpdater

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

the class TokenIndexAccessorTest method doRandomizedUpdatesWithAdditionalOperation.

private void doRandomizedUpdatesWithAdditionalOperation(Executable additionalOperation, MutableLongObjectMap<long[]> trackingStructure) throws Throwable {
    int numberOfEntities = 1_000;
    long currentMaxEntityId = 0;
    while (currentMaxEntityId < numberOfEntities) {
        try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
            // Simply add random token ids to a new batch of 100 entities
            for (int i = 0; i < 100; i++) {
                long[] afterTokens = generateRandomTokens(random);
                if (afterTokens.length != 0) {
                    trackingStructure.put(currentMaxEntityId, Arrays.copyOf(afterTokens, afterTokens.length));
                    updater.process(IndexEntryUpdate.change(currentMaxEntityId, null, EMPTY_LONG_ARRAY, afterTokens));
                }
                currentMaxEntityId++;
            }
        }
        additionalOperation.execute();
        // Interleave updates in id range lower than currentMaxEntityId
        try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
            for (int i = 0; i < 100; i++) {
                long entityId = random.nextLong(currentMaxEntityId);
                // Current tokens for the entity in the tree
                long[] beforeTokens = trackingStructure.get(entityId);
                if (beforeTokens == null) {
                    beforeTokens = EMPTY_LONG_ARRAY;
                }
                long[] afterTokens = generateRandomTokens(random);
                trackingStructure.put(entityId, Arrays.copyOf(afterTokens, afterTokens.length));
                updater.process(IndexEntryUpdate.change(entityId, null, beforeTokens, afterTokens));
            }
        }
        additionalOperation.execute();
    }
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 90 with IndexUpdater

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

the class NativeUniqueIndexPopulatorTest method updaterShouldThrowOnDuplicateValues.

@Test
void updaterShouldThrowOnDuplicateValues() throws Exception {
    // given
    populator.create();
    IndexEntryUpdate<IndexDescriptor>[] updates = valueCreatorUtil.someUpdatesWithDuplicateValues(random);
    IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL);
    // when
    for (IndexEntryUpdate<IndexDescriptor> update : updates) {
        updater.process(update);
    }
    var e = assertThrows(Exception.class, () -> {
        updater.close();
        populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    });
    assertTrue(hasCause(e, IndexEntryConflictException.class), e.getMessage());
    populator.close(true, NULL);
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) 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