Search in sources :

Example 1 with ValueIndexEntryUpdate

use of org.neo4j.storageengine.api.ValueIndexEntryUpdate 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 2 with ValueIndexEntryUpdate

use of org.neo4j.storageengine.api.ValueIndexEntryUpdate 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 3 with ValueIndexEntryUpdate

use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.

the class SimpleIndexAccessorCompatibility method shouldRangeSeekInOrderWithExpectedSize.

private void shouldRangeSeekInOrderWithExpectedSize(IndexOrder order, RangeSeekMode rangeSeekMode, int expectedSize, Object... objects) throws Exception {
    PropertyIndexQuery range;
    switch(rangeSeekMode) {
        case CLOSED:
            range = range(100, Values.of(objects[0]), true, Values.of(objects[objects.length - 1]), true);
            break;
        case OPEN_END:
            range = range(100, Values.of(objects[0]), true, null, false);
            break;
        case OPEN_START:
            range = range(100, null, false, Values.of(objects[objects.length - 1]), true);
            break;
        default:
            throw new IllegalStateException();
    }
    IndexOrderCapability indexOrders = orderCapability(range);
    if (order == IndexOrder.ASCENDING) {
        Assume.assumeTrue("Assume support for order " + order, indexOrders.supportsAsc());
    } else if (order == IndexOrder.DESCENDING) {
        Assume.assumeTrue("Assume support for order " + order, indexOrders.supportsDesc());
    }
    List<ValueIndexEntryUpdate<?>> additions = Arrays.stream(objects).map(o -> add(1, descriptor.schema(), o)).collect(Collectors.toList());
    Collections.shuffle(additions, random.random());
    updateAndCommit(additions);
    SimpleEntityValueClient client = new SimpleEntityValueClient();
    try (AutoCloseable ignored = query(client, order, range)) {
        List<Long> seenIds = assertClientReturnValuesInOrder(client, order);
        assertThat(seenIds.size()).isEqualTo(expectedSize);
    }
}
Also used : IndexOrder(org.neo4j.internal.schema.IndexOrder) Arrays(java.util.Arrays) ArrayValue(org.neo4j.values.storable.ArrayValue) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ZonedDateTime(java.time.ZonedDateTime) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Value(org.neo4j.values.storable.Value) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) PropertyIndexQuery.exists(org.neo4j.internal.kernel.api.PropertyIndexQuery.exists) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) EMPTY_LIST(java.util.Collections.EMPTY_LIST) OffsetTime(java.time.OffsetTime) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) DateTimeValue.datetime(org.neo4j.values.storable.DateTimeValue.datetime) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Collectors(java.util.stream.Collectors) PointValue(org.neo4j.values.storable.PointValue) ZoneId(java.time.ZoneId) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) List(java.util.List) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) ReporterFactories(org.neo4j.annotations.documented.ReporterFactories) PropertyIndexQuery.exact(org.neo4j.internal.kernel.api.PropertyIndexQuery.exact) LocalDateTime(java.time.LocalDateTime) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) PropertyIndexQuery.range(org.neo4j.internal.kernel.api.PropertyIndexQuery.range) Assume(org.junit.Assume) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) LocalDateTimeValue.localDateTime(org.neo4j.values.storable.LocalDateTimeValue.localDateTime) LocalTimeValue.localTime(org.neo4j.values.storable.LocalTimeValue.localTime) ValueType(org.neo4j.values.storable.ValueType) IndexQueryHelper.add(org.neo4j.kernel.api.index.IndexQueryHelper.add) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) PropertyIndexQuery.stringPrefix(org.neo4j.internal.kernel.api.PropertyIndexQuery.stringPrefix) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeValue.time(org.neo4j.values.storable.TimeValue.time) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PropertyIndexQuery.stringSuffix(org.neo4j.internal.kernel.api.PropertyIndexQuery.stringSuffix) DateValue.epochDate(org.neo4j.values.storable.DateValue.epochDate) DurationValue.duration(org.neo4j.values.storable.DurationValue.duration) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) DateValue(org.neo4j.values.storable.DateValue) PropertyIndexQuery.stringContains(org.neo4j.internal.kernel.api.PropertyIndexQuery.stringContains) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 4 with ValueIndexEntryUpdate

use of org.neo4j.storageengine.api.ValueIndexEntryUpdate in project neo4j by neo4j.

the class NativeIndexAccessorTests method shouldNotSeeFilteredEntries.

@Test
void shouldNotSeeFilteredEntries() throws Exception {
    // given
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleTypeNoDuplicates(supportedTypesExcludingNonOrderable());
    processAll(updates);
    ValueCreatorUtil.sort(updates);
    var reader = accessor.newValueReader();
    // when
    try (NodeValueIterator iter = new NodeValueIterator()) {
        PropertyIndexQuery.ExactPredicate filter = PropertyIndexQuery.exact(0, valueOf(updates[1]));
        PropertyIndexQuery rangeQuery = ValueCreatorUtil.rangeQuery(valueOf(updates[0]), true, valueOf(updates[2]), true);
        IndexProgressor.EntityValueClient filterClient = filterClient(iter, filter);
        reader.query(NULL_CONTEXT, filterClient, unconstrained(), rangeQuery);
        // then
        assertTrue(iter.hasNext());
        assertEquals(entityIdOf(updates[1]), iter.next());
        assertFalse(iter.hasNext());
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Test(org.junit.jupiter.api.Test)

Example 5 with ValueIndexEntryUpdate

use of org.neo4j.storageengine.api.ValueIndexEntryUpdate 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)

Aggregations

ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)26 Test (org.junit.jupiter.api.Test)15 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)11 Value (org.neo4j.values.storable.Value)11 ArrayList (java.util.ArrayList)9 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)9 PointValue (org.neo4j.values.storable.PointValue)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)5 ValueType (org.neo4j.values.storable.ValueType)5 List (java.util.List)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Random (java.util.Random)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 MutableLong (org.apache.commons.lang3.mutable.MutableLong)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)2