Search in sources :

Example 31 with IndexUpdater

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

the class RelationshipCheckerWithRelationshipTypeIndexTest method doVerifyCorrectReport.

@SafeVarargs
private void doVerifyCorrectReport(Density density, ThrowingConsumer<IndexUpdater, IndexEntryConflictException> targetRelationshipAction, Consumer<ConsistencyReport.RelationshipTypeScanConsistencyReport>... expectedCalls) throws Exception {
    double recordFrequency = densityAsFrequency(density);
    int nbrOfRelationships = random.nextInt(1, 2 * IDS_PER_CHUNK);
    int targetRelationshipRelationship = random.nextInt(nbrOfRelationships);
    // given
    try (Transaction tx = db.beginTx();
        IndexUpdater writer = relationshipTypeIndexWriter()) {
        for (int i = 0; i < nbrOfRelationships; i++) {
            if (i == targetRelationshipRelationship) {
                targetRelationshipAction.accept(writer);
            } else {
                if (random.nextDouble() < recordFrequency) {
                    createCompleteEntry(writer, type);
                } else {
                    notInUse(createStoreEntry(type));
                }
            }
        }
        tx.commit();
    }
    // when
    ConsistencyFlags flags = new ConsistencyFlags(true, true, true);
    check(context(flags));
    // then
    if (expectedCalls != null) {
        for (Consumer<ConsistencyReport.RelationshipTypeScanConsistencyReport> expectedCall : expectedCalls) {
            expect(ConsistencyReport.RelationshipTypeScanConsistencyReport.class, expectedCall);
        }
    } else {
        verifyNoInteractions(monitor);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport)

Example 32 with IndexUpdater

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

the class FullCheckIntegrationTest method writeToNodeLabelStructure.

void writeToNodeLabelStructure(GraphStoreFixture fixture, Iterable<EntityTokenUpdate> entityTokenUpdates) throws IOException, IndexEntryConflictException {
    IndexDescriptor tokenIndex = findTokenIndex(fixture, EntityType.NODE);
    IndexAccessor accessor = fixture.indexAccessorLookup().apply(tokenIndex);
    try (IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        for (EntityTokenUpdate entityTokenUpdate : entityTokenUpdates) {
            indexUpdater.process(IndexEntryUpdate.change(entityTokenUpdate.getEntityId(), tokenIndex, entityTokenUpdate.getTokensBefore(), entityTokenUpdate.getTokensAfter()));
        }
    }
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) EntityTokenUpdate(org.neo4j.storageengine.api.EntityTokenUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 33 with IndexUpdater

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

the class FullCheckIntegrationTest method shouldReportNodesWithDuplicatePropertyValueInUniqueIndex.

@ParameterizedTest
@EnumSource(IndexSize.class)
void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex(IndexSize indexSize) throws Exception {
    // given
    indexSize.createAdditionalData(fixture);
    Iterator<IndexDescriptor> indexRuleIterator = getValueIndexDescriptors();
    // Create a node so the duplicate in the index refers to a valid node
    // (IndexChecker only reports the duplicate if it refers to a node id lower than highId)
    long nodeId = createOneNode();
    while (indexRuleIterator.hasNext()) {
        IndexDescriptor indexRule = indexRuleIterator.next();
        // Don't close this accessor. It will be done when shutting down db.
        IndexAccessor accessor = fixture.indexAccessorLookup().apply(indexRule);
        try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            // There is already another node (created in generateInitialData()) that has this value
            updater.process(IndexEntryUpdate.add(nodeId, indexRule.schema(), values(indexRule)));
        }
        accessor.force(NULL);
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    // the duplicate in unique index
    on(stats).verify(RecordType.NODE, 1).verify(RecordType.INDEX, // the index entries pointing to node that should not be in index
    3).andThatsAllFolks();
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) 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 34 with IndexUpdater

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

the class LuceneIndexAccessorIT method removeSomeNodes.

private static void removeSomeNodes(IndexDescriptor indexDescriptor, int nodes, IndexAccessor accessor, MutableLongSet expectedNodes) throws IndexEntryConflictException {
    try (IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        for (long id = 0; id < nodes; id++) {
            updater.process(IndexEntryUpdate.remove(id, indexDescriptor, values(indexDescriptor, id)));
            expectedNodes.remove(id);
        }
    }
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Example 35 with IndexUpdater

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

the class FusionIndexUpdater method process.

@Override
public void process(IndexEntryUpdate<?> update) throws IndexEntryConflictException {
    ValueIndexEntryUpdate<?> valueUpdate = asValueUpdate(update);
    switch(valueUpdate.updateMode()) {
        case ADDED:
            instanceSelector.select(slotSelector.selectSlot(valueUpdate.values(), CATEGORY_OF)).process(valueUpdate);
            break;
        case CHANGED:
            // Hmm, here's a little conundrum. What if we change from a value that goes into native
            // to a value that goes into fallback, or vice versa? We also don't want to blindly pass
            // all CHANGED updates to both updaters since not all values will work in them.
            IndexUpdater from = instanceSelector.select(slotSelector.selectSlot(valueUpdate.beforeValues(), CATEGORY_OF));
            IndexUpdater to = instanceSelector.select(slotSelector.selectSlot(valueUpdate.values(), CATEGORY_OF));
            // - both before/after go into the same updater --> pass update into that updater
            if (from == to) {
                from.process(valueUpdate);
            } else // - before go into one and after into the other --> REMOVED from one and ADDED into the other
            {
                from.process(IndexEntryUpdate.remove(valueUpdate.getEntityId(), valueUpdate.indexKey(), valueUpdate.beforeValues()));
                to.process(IndexEntryUpdate.add(valueUpdate.getEntityId(), valueUpdate.indexKey(), valueUpdate.values()));
            }
            break;
        case REMOVED:
            instanceSelector.select(slotSelector.selectSlot(valueUpdate.values(), CATEGORY_OF)).process(valueUpdate);
            break;
        default:
            throw new IllegalArgumentException("Unknown update mode");
    }
}
Also used : IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

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