Search in sources :

Example 66 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater 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 67 with IndexUpdater

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

the class UniqueDatabaseIndexPopulatorTest method shouldUpdateEntryForNodeThatHasAlreadyBeenIndexed.

@Test
void shouldUpdateEntryForNodeThatHasAlreadyBeenIndexed() throws Exception {
    // given
    populator = newPopulator();
    addUpdate(populator, 1, "value1");
    // when
    IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
    updater.process(change(1, schemaDescriptor, "value1", "value2"));
    populator.close(true, NULL);
    // then
    assertEquals(Collections.EMPTY_LIST, getAllNodes(getDirectory(), "value1"));
    assertEquals(singletonList(1L), getAllNodes(getDirectory(), "value2"));
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 68 with IndexUpdater

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

the class UniqueDatabaseIndexPopulatorTest method shouldRejectDuplicateEntryAfterUsingPopulatingUpdater.

@Test
void shouldRejectDuplicateEntryAfterUsingPopulatingUpdater() throws Exception {
    // given
    populator = newPopulator();
    String valueString = "value1";
    IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
    updater.process(add(1, schemaDescriptor, valueString));
    addUpdate(populator, 2, valueString);
    Value value = Values.of(valueString);
    when(nodePropertyAccessor.getNodePropertyValue(1, PROPERTY_KEY_ID, NULL)).thenReturn(value);
    when(nodePropertyAccessor.getNodePropertyValue(2, PROPERTY_KEY_ID, NULL)).thenReturn(value);
    // when
    var conflict = assertThrows(IndexEntryConflictException.class, () -> populator.verifyDeferredConstraints(nodePropertyAccessor));
    assertEquals(1, conflict.getExistingNodeId());
    assertEquals(value, conflict.getSinglePropertyValue());
    assertEquals(2, conflict.getAddedNodeId());
}
Also used : Value(org.neo4j.values.storable.Value) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 69 with IndexUpdater

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

the class UniqueDatabaseIndexPopulatorTest method shouldRejectDuplicateEntryWhenUsingPopulatingUpdater.

@Test
void shouldRejectDuplicateEntryWhenUsingPopulatingUpdater() throws Exception {
    // given
    populator = newPopulator();
    addUpdate(populator, 1, "value1");
    addUpdate(populator, 2, "value2");
    Value value = Values.of("value1");
    when(nodePropertyAccessor.getNodePropertyValue(1, PROPERTY_KEY_ID, NULL)).thenReturn(value);
    when(nodePropertyAccessor.getNodePropertyValue(3, PROPERTY_KEY_ID, NULL)).thenReturn(value);
    // when
    var conflict = assertThrows(IndexEntryConflictException.class, () -> {
        IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL);
        updater.process(add(3, schemaDescriptor, "value1"));
        updater.close();
    });
    assertEquals(1, conflict.getExistingNodeId());
    assertEquals(value, conflict.getSinglePropertyValue());
    assertEquals(3, conflict.getAddedNodeId());
}
Also used : Value(org.neo4j.values.storable.Value) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 70 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater 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)

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