Search in sources :

Example 16 with ValueIndexEntryUpdate

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

the class SimpleIndexAccessorCompatibility method testIndexRangeSeek.

private void testIndexRangeSeek(Supplier<? extends Value> generator) throws Exception {
    int count = random.nextInt(5, 10);
    List<Value> values = new ArrayList<>();
    List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    Set<Value> duplicateCheck = new HashSet<>();
    for (int i = 0; i < count; i++) {
        Value value;
        do {
            value = generator.get();
        } while (!duplicateCheck.add(value));
        values.add(value);
    }
    values.sort(Values.COMPARATOR);
    for (int i = 0; i < count; i++) {
        updates.add(add(i + 1, descriptor.schema(), values.get(i)));
    }
    // <- Don't rely on insert order
    Collections.shuffle(updates);
    updateAndCommit(updates);
    for (int f = 0; f < values.size(); f++) {
        for (int t = f; t < values.size(); t++) {
            Value from = values.get(f);
            Value to = values.get(t);
            for (boolean fromInclusive : new boolean[] { true, false }) {
                for (boolean toInclusive : new boolean[] { true, false }) {
                    assertThat(query(range(1, from, fromInclusive, to, toInclusive))).isEqualTo(ids(f, fromInclusive, t, toInclusive));
                }
            }
        }
    }
}
Also used : ArrayValue(org.neo4j.values.storable.ArrayValue) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) DateValue(org.neo4j.values.storable.DateValue) ArrayList(java.util.ArrayList) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) HashSet(java.util.HashSet)

Example 17 with ValueIndexEntryUpdate

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

the class SimpleIndexPopulatorCompatibility method shouldPopulateAndUpdate.

@Test
public void shouldPopulateAndUpdate() throws Exception {
    // GIVEN
    withPopulator(indexProvider.getPopulator(descriptor, indexSamplingConfig, heapBufferFactory(1024), INSTANCE, tokenNameLookup), p -> p.add(updates(valueSet1), NULL));
    try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, indexSamplingConfig, tokenNameLookup)) {
        // WHEN
        try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            List<ValueIndexEntryUpdate<?>> updates = updates(valueSet2);
            for (ValueIndexEntryUpdate<?> update : updates) {
                updater.process(update);
            }
        }
        // THEN
        try (ValueIndexReader reader = accessor.newValueReader()) {
            int propertyKeyId = descriptor.schema().getPropertyId();
            for (NodeAndValue entry : Iterables.concat(valueSet1, valueSet2)) {
                try (NodeValueIterator nodes = new NodeValueIterator()) {
                    reader.query(NULL_CONTEXT, nodes, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, entry.value));
                    assertEquals(entry.nodeId, nodes.next());
                    assertFalse(nodes.hasNext());
                }
            }
        }
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Test(org.junit.Test)

Example 18 with ValueIndexEntryUpdate

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

the class BlockBasedIndexPopulator method newPopulatingUpdater.

@Override
public IndexUpdater newPopulatingUpdater(CursorContext cursorContext) {
    if (scanCompleted) {
        // Will need the reader from newReader, which a sub-class of this class implements
        return new DelegatingIndexUpdater(super.newPopulatingUpdater(cursorContext)) {

            @Override
            public void process(IndexEntryUpdate<?> update) throws IndexEntryConflictException {
                ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
                validateUpdate(valueUpdate);
                numberOfIndexUpdatesSinceSample.incrementAndGet();
                super.process(valueUpdate);
            }
        };
    }
    return new IndexUpdater() {

        private volatile boolean closed;

        @Override
        public void process(IndexEntryUpdate<?> update) {
            assertOpen();
            ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
            try {
                validateUpdate(valueUpdate);
                externalUpdates.add(valueUpdate);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        @Override
        public void close() {
            closed = true;
        }

        private void assertOpen() {
            if (closed) {
                throw new IllegalStateException("Updater has been closed");
            }
        }
    };
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) DelegatingIndexUpdater(org.neo4j.kernel.impl.api.index.updater.DelegatingIndexUpdater) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) DelegatingIndexUpdater(org.neo4j.kernel.impl.api.index.updater.DelegatingIndexUpdater)

Example 19 with ValueIndexEntryUpdate

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

the class FullCheckIntegrationTest method shouldReportNodesThatAreNotIndexed.

@ParameterizedTest
@EnumSource(IndexSize.class)
void shouldReportNodesThatAreNotIndexed(IndexSize indexSize) throws Exception {
    indexSize.createAdditionalData(fixture);
    // given
    Iterator<IndexDescriptor> indexDescriptorIterator = getValueIndexDescriptors();
    while (indexDescriptorIterator.hasNext()) {
        IndexDescriptor indexDescriptor = indexDescriptorIterator.next();
        IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexDescriptor);
        try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            for (long nodeId : indexedNodes) {
                EntityUpdates updates = fixture.nodeAsUpdates(nodeId);
                for (IndexEntryUpdate<?> update : updates.valueUpdatesForIndexKeys(singletonList(indexDescriptor))) {
                    updater.process(IndexEntryUpdate.remove(nodeId, indexDescriptor, ((ValueIndexEntryUpdate<?>) update).values()));
                }
            }
        }
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    // 1 node missing from 1 index + 1 node missing from 2 indexes
    on(stats).verify(RecordType.NODE, 3).andThatsAllFolks();
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with ValueIndexEntryUpdate

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

the class IndexUpdateStorage method add.

@Override
public void add(IndexEntryUpdate<?> update, PageCursor pageCursor) throws IOException {
    ValueIndexEntryUpdate<?> valueUpdate = (ValueIndexEntryUpdate<?>) update;
    int entrySize = TYPE_SIZE;
    UpdateMode updateMode = valueUpdate.updateMode();
    switch(updateMode) {
        case ADDED:
            initializeKeyAndValueFromUpdate(key1, value, valueUpdate.getEntityId(), valueUpdate.values());
            entrySize += BlockEntry.entrySize(layout, key1, value);
            break;
        case REMOVED:
            initializeKeyFromUpdate(key1, valueUpdate.getEntityId(), valueUpdate.values());
            entrySize += BlockEntry.keySize(layout, key1);
            break;
        case CHANGED:
            initializeKeyFromUpdate(key1, valueUpdate.getEntityId(), valueUpdate.beforeValues());
            initializeKeyAndValueFromUpdate(key2, value, valueUpdate.getEntityId(), valueUpdate.values());
            entrySize += BlockEntry.keySize(layout, key1) + BlockEntry.entrySize(layout, key2, value);
            break;
        default:
            throw new IllegalArgumentException("Unknown update mode " + updateMode);
    }
    prepareWrite(entrySize);
    pageCursor.putByte((byte) updateMode.ordinal());
    IndexUpdateEntry.write(pageCursor, layout, updateMode, key1, key2, value);
}
Also used : UpdateMode(org.neo4j.storageengine.api.UpdateMode) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate)

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