Search in sources :

Example 6 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class NodeSchemaMatcher method onMatchingSchema.

/**
     * Iterate over some schema suppliers, and invoke an action for every supplier that matches the node. To match the
     * node N the supplier must supply a LabelSchemaDescriptor D, such that N has the label of D, and values for all
     * the properties of D.
     *
     * To avoid unnecessary store lookups, this implementation only gets propertyKeyIds for the node if some
     * descriptor has a valid label.
     *
     * @param state The current statement
     * @param schemaSuppliers The suppliers to match
     * @param node The node
     * @param specialPropertyId This property id will always count as a match for the descriptor, regardless of
     *                          whether the node has this property or not
     * @param action The action to take on match
     * @param <EXCEPTION> The type of exception that can be thrown when taking the action
     * @throws EXCEPTION This exception is propagated from the action
     */
public <EXCEPTION extends Exception> void onMatchingSchema(KernelStatement state, Iterator<SUPPLIER> schemaSuppliers, NodeItem node, int specialPropertyId, SchemaMatchAction<SUPPLIER, EXCEPTION> action) throws EXCEPTION {
    PrimitiveIntSet nodePropertyIds = null;
    while (schemaSuppliers.hasNext()) {
        SUPPLIER schemaSupplier = schemaSuppliers.next();
        LabelSchemaDescriptor schema = schemaSupplier.schema();
        if (node.labels().contains(schema.getLabelId())) {
            if (nodePropertyIds == null) {
                nodePropertyIds = Primitive.intSet();
                nodePropertyIds.addAll(readOps.nodeGetPropertyKeys(state, node).iterator());
            }
            if (nodeHasSchemaProperties(nodePropertyIds, schema.getPropertyIds(), specialPropertyId)) {
                action.act(schemaSupplier);
            }
        }
    }
}
Also used : PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 7 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class IndexTxStateUpdater method onLabelChange.

public void onLabelChange(KernelStatement state, int labelId, NodeItem node, LabelChangeType changeType) throws EntityNotFoundException {
    PrimitiveIntSet nodePropertyIds = Primitive.intSet();
    nodePropertyIds.addAll(readOps.nodeGetPropertyKeys(state, node).iterator());
    Iterator<NewIndexDescriptor> indexes = Iterators.concat(schemaReadOps.indexesGetForLabel(state, labelId), schemaReadOps.uniqueIndexesGetForLabel(state, labelId));
    while (indexes.hasNext()) {
        NewIndexDescriptor index = indexes.next();
        int[] indexPropertyIds = index.schema().getPropertyIds();
        if (nodeHasIndexProperties(nodePropertyIds, indexPropertyIds)) {
            OrderedPropertyValues values = getOrderedPropertyValues(state, node, indexPropertyIds);
            if (changeType == LabelChangeType.ADDED_LABEL) {
                state.txState().indexDoUpdateEntry(index.schema(), node.id(), null, values);
            } else {
                state.txState().indexDoUpdateEntry(index.schema(), node.id(), values, null);
            }
        }
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues)

Example 8 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class PropertyChain method checkConsistency.

@Override
public void checkConsistency(RECORD record, CheckerEngine<RECORD, REPORT> engine, RecordAccess records) {
    if (!Record.NO_NEXT_PROPERTY.is(record.getNextProp())) {
        // Check the whole chain here instead of scattered during multiple checks.
        // This type of check obviously favors chains with good locality, performance-wise.
        Iterator<PropertyRecord> props = records.rawPropertyChain(record.getNextProp());
        PropertyRecord firstProp = props.next();
        if (!Record.NO_PREVIOUS_PROPERTY.is(firstProp.getPrevProp())) {
            engine.report().propertyNotFirstInChain(firstProp);
        }
        try (PrimitiveIntSet keys = Primitive.intSet();
            MandatoryProperties.Check<RECORD, REPORT> mandatory = mandatoryProperties.apply(record)) {
            checkChainItem(firstProp, engine, keys, mandatory);
            // Check the whole chain here. We also take the opportunity to check mandatory property constraints.
            while (props.hasNext()) {
                checkChainItem(props.next(), engine, keys, mandatory);
            }
        }
    }
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) MandatoryProperties(org.neo4j.consistency.checking.full.MandatoryProperties)

Example 9 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class PropertyAndNodeIndexedCheck method checkProperty.

private void checkProperty(NodeRecord record, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, Collection<PropertyRecord> props) {
    if (!Record.NO_NEXT_PROPERTY.is(record.getNextProp())) {
        PropertyRecord firstProp = props.iterator().next();
        if (!Record.NO_PREVIOUS_PROPERTY.is(firstProp.getPrevProp())) {
            engine.report().propertyNotFirstInChain(firstProp);
        }
        PrimitiveIntSet keys = Primitive.intSet();
        for (PropertyRecord property : props) {
            if (!property.inUse()) {
                engine.report().propertyNotInUse(property);
            } else {
                for (int key : ChainCheck.keys(property)) {
                    if (!keys.add(key)) {
                        engine.report().propertyKeyNotUniqueInChain();
                    }
                }
            }
        }
    }
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet)

Example 10 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class TransactionCountingStateVisitor method decrementCountForLabelsAndRelationships.

private void decrementCountForLabelsAndRelationships(NodeItem node) {
    PrimitiveIntSet labelIds = node.labels();
    labelIds.visitKeys(labelId -> {
        counts.incrementNodeCount(labelId, -1);
        return false;
    });
    storeLayer.degrees(statement, node, (type, out, in) -> updateRelationshipsCountsFromDegrees(labelIds, type, -out, -in));
}
Also used : PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet)

Aggregations

PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)14 Test (org.junit.Test)4 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)3 NodeItem (org.neo4j.storageengine.api.NodeItem)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Before (org.junit.Before)2 Statement (org.neo4j.kernel.api.Statement)2 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)2 EntityReadOperations (org.neo4j.kernel.impl.api.operations.EntityReadOperations)2 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Primitive (org.neo4j.collection.primitive.Primitive)1 PrimitiveIntCollection (org.neo4j.collection.primitive.PrimitiveIntCollection)1 PrimitiveIntCollections.filter (org.neo4j.collection.primitive.PrimitiveIntCollections.filter)1 PrimitiveIntIterator (org.neo4j.collection.primitive.PrimitiveIntIterator)1 PrimitiveIntStack (org.neo4j.collection.primitive.PrimitiveIntStack)1 PrimitiveLongCollections.resourceIterator (org.neo4j.collection.primitive.PrimitiveLongCollections.resourceIterator)1