Search in sources :

Example 1 with IndexUpdater

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

the class FullCheckIntegrationTest method shouldReportNodesThatAreNotIndexed.

@Test
public void shouldReportNodesThatAreNotIndexed() throws Exception {
    // given
    IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
    Iterator<IndexRule> indexRuleIterator = new SchemaStorage(fixture.directStoreAccess().nativeStores().getSchemaStore()).indexesGetAll();
    while (indexRuleIterator.hasNext()) {
        IndexRule indexRule = indexRuleIterator.next();
        IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor(indexRule.getId(), indexRule.getIndexDescriptor(), samplingConfig);
        IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE);
        updater.remove(asPrimitiveLongSet(indexedNodes));
        updater.close();
        accessor.close();
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.NODE, 1).andThatsAllFolks();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 2 with IndexUpdater

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

the class MultipleIndexPopulator method newPopulatingUpdater.

@Override
public MultipleIndexUpdater newPopulatingUpdater(PropertyAccessor accessor) {
    Map<LabelSchemaDescriptor, Pair<IndexPopulation, IndexUpdater>> updaters = new HashMap<>();
    forEachPopulation(population -> {
        IndexUpdater updater = population.populator.newPopulatingUpdater(accessor);
        updaters.put(population.descriptor.schema(), Pair.of(population, updater));
    });
    return new MultipleIndexUpdater(this, updaters, logProvider);
}
Also used : HashMap(java.util.HashMap) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.helpers.collection.Pair)

Example 3 with IndexUpdater

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

the class IndexUpdaterMap method getUpdater.

IndexUpdater getUpdater(LabelSchemaDescriptor descriptor) {
    IndexUpdater updater = updaterMap.get(descriptor);
    if (null == updater) {
        IndexProxy indexProxy = indexMap.getIndexProxy(descriptor);
        if (null != indexProxy) {
            updater = indexProxy.newUpdater(indexUpdateMode);
            updaterMap.put(descriptor, updater);
        }
    }
    return updater;
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 4 with IndexUpdater

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

the class FulltextIndexConsistencyCheckIT method mustDiscoverNodeInStoreMissingFromIndex.

@Test
void mustDiscoverNodeInStoreMissingFromIndex() throws Exception {
    GraphDatabaseService db = createDatabase();
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(NODE_CREATE, "nodes", asStrList("Label"), asStrList("prop"))).close();
        tx.commit();
    }
    IndexDescriptor indexDescriptor;
    long nodeId;
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        indexDescriptor = getFulltextIndexDescriptor(tx.schema().getIndexes());
        Node node = tx.createNode(Label.label("Label"));
        node.setProperty("prop", "value");
        nodeId = node.getId();
        tx.commit();
    }
    IndexingService indexes = getIndexingService(db);
    IndexProxy indexProxy = indexes.getIndexProxy(indexDescriptor);
    try (IndexUpdater updater = indexProxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(IndexEntryUpdate.remove(nodeId, indexDescriptor, Values.stringValue("value")));
    }
    managementService.shutdown();
    ConsistencyCheckService.Result result = checkConsistency();
    assertFalse(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Node(org.neo4j.graphdb.Node) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 5 with IndexUpdater

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

the class GenericBlockBasedIndexPopulatorTest method shouldThrowOnDuplicatedValuesFromScanAndExternalUpdates.

@Test
void shouldThrowOnDuplicatedValuesFromScanAndExternalUpdates() throws IOException {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(UNIQUE_INDEX_DESCRIPTOR);
    try {
        // when
        Value duplicate = Values.of("duplicate");
        ValueIndexEntryUpdate<?> externalUpdate = ValueIndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
        ValueIndexEntryUpdate<?> scanUpdate = ValueIndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
        assertThrows(IndexEntryConflictException.class, () -> {
            try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
                updater.process(externalUpdate);
            }
            populator.add(singleton(scanUpdate), NULL);
            populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
        });
    } finally {
        populator.close(true, NULL);
    }
}
Also used : Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) 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