Search in sources :

Example 11 with ValueIndexEntryUpdate

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

the class MultipleIndexPopulatorTest method updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan.

@Test
void updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan() throws IndexEntryConflictException, FlipFailedKernelException {
    // given
    createIndexPopulator();
    multipleIndexPopulator.create(NULL);
    IndexUpdater updater = mock(IndexUpdater.class);
    IndexPopulator populator = createIndexPopulator(updater);
    IndexUpdater indexUpdater = mock(IndexUpdater.class);
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(1, 1);
    addPopulator(populator, 1);
    // when external updates comes in
    ValueIndexEntryUpdate<LabelSchemaDescriptor> lowUpdate = IndexEntryUpdate.add(10, schema, intValue(99));
    ValueIndexEntryUpdate<LabelSchemaDescriptor> highUpdate = IndexEntryUpdate.add(20, schema, intValue(101));
    multipleIndexPopulator.queueConcurrentUpdate(lowUpdate);
    multipleIndexPopulator.queueConcurrentUpdate(highUpdate);
    // and we ask to apply them, given an entity in between the two
    multipleIndexPopulator.applyExternalUpdates(15);
    // then only the lower one should be applied, the higher one ignored
    verify(populator, times(1)).newPopulatingUpdater(any(), any());
    verify(updater).process(lowUpdate);
    verify(updater, never()).process(highUpdate);
    verify(indexUpdater, never()).process(any(IndexEntryUpdate.class));
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 12 with ValueIndexEntryUpdate

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

the class SimpleRandomizedIndexAccessorCompatibility method testExactMatchOnRandomValues.

@Test
public void testExactMatchOnRandomValues() throws Exception {
    // given
    ValueType[] types = randomSetOfSupportedTypes();
    List<Value> values = generateValuesFromType(types, new HashSet<>(), 30_000);
    List<ValueIndexEntryUpdate<?>> updates = generateUpdatesFromValues(values, new MutableLong());
    updateAndCommit(updates);
    // when
    for (ValueIndexEntryUpdate<?> update : updates) {
        // then
        List<Long> hits = query(PropertyIndexQuery.exact(0, update.values()[0]));
        assertEquals(hits.toString(), 1, hits.size());
        assertThat(single(hits)).isEqualTo(update.getEntityId());
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) ValueType(org.neo4j.values.storable.ValueType) Value(org.neo4j.values.storable.Value) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 13 with ValueIndexEntryUpdate

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

the class SimpleRandomizedIndexAccessorCompatibility method testRangeMatchInOrderOnRandomValues.

@Test
public void testRangeMatchInOrderOnRandomValues() throws Exception {
    Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
    // given
    ValueType[] types = randomSetOfSupportedAndSortableTypes();
    Set<Value> uniqueValues = new HashSet<>();
    TreeSet<ValueAndId> sortedValues = new TreeSet<>((v1, v2) -> Values.COMPARATOR.compare(v1.value, v2.value));
    MutableLong nextId = new MutableLong();
    // A couple of rounds of updates followed by lots of range verifications
    for (int i = 0; i < 5; i++) {
        List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
        if (i == 0) {
            // The initial batch of data can simply be additions
            updates = generateUpdatesFromValues(generateValuesFromType(types, uniqueValues, 20_000), nextId);
            sortedValues.addAll(updates.stream().map(u -> new ValueAndId(u.values()[0], u.getEntityId())).collect(Collectors.toList()));
        } else {
            // Then do all sorts of updates
            for (int j = 0; j < 1_000; j++) {
                int type = random.intBetween(0, 2);
                if (type == 0) {
                    // add
                    Value value = generateUniqueRandomValue(types, uniqueValues);
                    long id = nextId.getAndIncrement();
                    sortedValues.add(new ValueAndId(value, id));
                    updates.add(add(id, descriptor.schema(), value));
                } else if (type == 1) {
                    // update
                    ValueAndId existing = random.among(sortedValues.toArray(new ValueAndId[0]));
                    sortedValues.remove(existing);
                    Value newValue = generateUniqueRandomValue(types, uniqueValues);
                    uniqueValues.remove(existing.value);
                    sortedValues.add(new ValueAndId(newValue, existing.id));
                    updates.add(change(existing.id, descriptor.schema(), existing.value, newValue));
                } else {
                    // remove
                    ValueAndId existing = random.among(sortedValues.toArray(new ValueAndId[0]));
                    sortedValues.remove(existing);
                    uniqueValues.remove(existing.value);
                    updates.add(remove(existing.id, descriptor.schema(), existing.value));
                }
            }
        }
        updateAndCommit(updates);
        verifyRandomRanges(types, sortedValues);
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) MutableLong(org.apache.commons.lang3.mutable.MutableLong) TreeSet(java.util.TreeSet) Value(org.neo4j.values.storable.Value) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with ValueIndexEntryUpdate

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

the class SimpleRandomizedIndexAccessorCompatibility method generateUpdatesFromValues.

private List<ValueIndexEntryUpdate<?>> generateUpdatesFromValues(List<Value> values, MutableLong nextId) {
    List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    for (Value value : values) {
        ValueIndexEntryUpdate<SchemaDescriptor> update = add(nextId.getAndIncrement(), descriptor.schema(), value);
        updates.add(update);
    }
    return updates;
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value)

Example 15 with ValueIndexEntryUpdate

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

the class CompositeIndexAccessorCompatibility method testExactMatchOnRandomCompositeValues.

@Test
public void testExactMatchOnRandomCompositeValues() throws Exception {
    // given
    ValueType[] types = randomSetOfSupportedTypes();
    List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    Set<ValueTuple> duplicateChecker = new HashSet<>();
    for (long id = 0; id < 10_000; id++) {
        ValueIndexEntryUpdate<SchemaDescriptor> update;
        do {
            update = add(id, descriptor.schema(), random.randomValues().nextValueOfTypes(types), random.randomValues().nextValueOfTypes(types));
        } while (!duplicateChecker.add(ValueTuple.of(update.values())));
        updates.add(update);
    }
    updateAndCommit(updates);
    // when
    InMemoryTokens tokenNameLookup = new InMemoryTokens();
    for (ValueIndexEntryUpdate<?> update : updates) {
        // then
        List<Long> hits = query(exact(0, update.values()[0]), exact(1, update.values()[1]));
        assertEquals(update.describe(tokenNameLookup) + " " + hits, 1, hits.size());
        assertThat(single(hits)).isEqualTo(update.getEntityId());
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) InMemoryTokens(org.neo4j.test.InMemoryTokens) ValueType(org.neo4j.values.storable.ValueType) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) ValueTuple(org.neo4j.values.storable.ValueTuple) HashSet(java.util.HashSet) Test(org.junit.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