Search in sources :

Example 6 with IndexUpdater

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

the class IndexPopulationStressTest method updater.

private Runnable updater(AtomicReferenceArray<List<ValueIndexEntryUpdate<?>>> lastBatches, CountDownLatch insertersDone, ReadWriteLock updateLock, Collection<ValueIndexEntryUpdate<?>> updates) {
    return throwing(() -> {
        // Entity ids that have been removed, so that additions can reuse them
        List<Long> removed = new ArrayList<>();
        RandomValues randomValues = RandomValues.create(new Random(random.seed() + THREADS));
        while (insertersDone.getCount() > 0) {
            // Do updates now and then
            Thread.sleep(10);
            updateLock.writeLock().lock();
            try (IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL)) {
                for (int i = 0; i < THREADS; i++) {
                    List<ValueIndexEntryUpdate<?>> batch = lastBatches.get(i);
                    if (batch != null) {
                        ValueIndexEntryUpdate<?> update = null;
                        switch(randomValues.nextInt(3)) {
                            case // add
                            0:
                                if (!removed.isEmpty()) {
                                    Long id = removed.remove(randomValues.nextInt(removed.size()));
                                    update = add(id, descriptor, valueGenerator.apply(randomValues));
                                }
                                break;
                            case // remove
                            1:
                                ValueIndexEntryUpdate<?> removal = batch.get(randomValues.nextInt(batch.size()));
                                update = remove(removal.getEntityId(), descriptor, removal.values());
                                removed.add(removal.getEntityId());
                                break;
                            case // change
                            2:
                                removal = batch.get(randomValues.nextInt(batch.size()));
                                change(removal.getEntityId(), descriptor, removal.values(), toArray(valueGenerator.apply(randomValues)));
                                break;
                            default:
                                throw new IllegalArgumentException();
                        }
                        if (update != null) {
                            updater.process(update);
                            updates.add(update);
                        }
                    }
                }
            } finally {
                updateLock.writeLock().unlock();
            }
        }
    });
}
Also used : Random(java.util.Random) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArrayList(java.util.ArrayList) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) RandomValues(org.neo4j.values.storable.RandomValues) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 7 with IndexUpdater

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

the class IndexPopulationStressTest method buildReferencePopulatorSingleThreaded.

private void buildReferencePopulatorSingleThreaded(Generator[] generators, Collection<ValueIndexEntryUpdate<?>> updates) throws IndexEntryConflictException, IOException {
    IndexPopulator referencePopulator = indexProvider.getPopulator(descriptor2, samplingConfig, heapBufferFactory((int) kibiBytes(40)), INSTANCE, tokenNameLookup);
    referencePopulator.create();
    boolean referenceSuccess = false;
    try {
        for (Generator generator : generators) {
            generator.reset();
            for (int i = 0; i < BATCHES_PER_THREAD; i++) {
                referencePopulator.add(generator.batch(), NULL);
            }
        }
        try (IndexUpdater updater = referencePopulator.newPopulatingUpdater(nodePropertyAccessor, NULL)) {
            for (ValueIndexEntryUpdate<?> update : updates) {
                updater.process(update);
            }
        }
        referenceSuccess = true;
    } finally {
        referencePopulator.close(referenceSuccess, NULL);
    }
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 8 with IndexUpdater

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

the class DeferredConflictCheckingIndexUpdaterTest method shouldQueryAboutAddedAndChangedValueTuples.

@Test
void shouldQueryAboutAddedAndChangedValueTuples() throws Exception {
    // given
    IndexUpdater actual = mock(IndexUpdater.class);
    ValueIndexReader reader = mock(ValueIndexReader.class);
    doAnswer(new NodeIdsIndexReaderQueryAnswer(descriptor, 0)).when(reader).query(any(), any(), any(), any(), any());
    long nodeId = 0;
    List<ValueIndexEntryUpdate<IndexDescriptor>> updates = new ArrayList<>();
    updates.add(add(nodeId++, descriptor, tuple(10, 11)));
    updates.add(change(nodeId++, descriptor, tuple("abc", "def"), tuple("ghi", "klm")));
    updates.add(remove(nodeId++, descriptor, tuple(1001L, 1002L)));
    updates.add(change(nodeId++, descriptor, tuple((byte) 2, (byte) 3), tuple((byte) 4, (byte) 5)));
    updates.add(add(nodeId, descriptor, tuple(5, "5")));
    try (DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater(actual, () -> reader, descriptor, NULL)) {
        // when
        for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
            updater.process(update);
            verify(actual).process(update);
        }
    }
    // then
    for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
        if (update.updateMode() == UpdateMode.ADDED || update.updateMode() == UpdateMode.CHANGED) {
            Value[] tuple = update.values();
            PropertyIndexQuery[] query = new PropertyIndexQuery[tuple.length];
            for (int i = 0; i < tuple.length; i++) {
                query[i] = PropertyIndexQuery.exact(propertyKeyIds[i], tuple[i]);
            }
            verify(reader).query(any(), any(), any(), eq(query[0]), eq(query[1]));
        }
    }
    verify(reader).close();
    verifyNoMoreInteractions(reader);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) Value(org.neo4j.values.storable.Value) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Test(org.junit.jupiter.api.Test)

Example 9 with IndexUpdater

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

the class NativeIndexAccessorTests method processMustThrowAfterClose.

// UPDATER
@Test
void processMustThrowAfterClose() throws Exception {
    // given
    IndexUpdater updater = accessor.newUpdater(ONLINE, NULL);
    updater.close();
    assertThrows(IllegalStateException.class, () -> updater.process(simpleUpdate()));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 10 with IndexUpdater

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

the class NativeIndexPopulatorTests method updaterShouldApplyUpdates.

@Test
void updaterShouldApplyUpdates() throws Exception {
    // given
    populator.create();
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = valueCreatorUtil.someUpdates(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