Search in sources :

Example 31 with SchemaDescriptor

use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.

the class Operations method constraintDrop.

@Override
public void constraintDrop(SchemaDescriptor schema, ConstraintType type) throws SchemaKernelException {
    ktx.assertOpen();
    Iterator<ConstraintDescriptor> constraints = ktx.schemaRead().constraintsGetForSchema(schema);
    constraints = Iterators.filter(constraint -> constraint.type() == type, constraints);
    if (constraints.hasNext()) {
        ConstraintDescriptor constraint = constraints.next();
        if (!constraints.hasNext()) {
            constraintDrop(constraint);
        } else {
            String schemaDescription = schema.userDescription(token);
            String constraintDescription = constraints.next().userDescription(token);
            throw new DropConstraintFailureException(constraint, new IllegalArgumentException("More than one " + type + " constraint was found with the '" + schemaDescription + "' schema: " + constraintDescription + ", please drop constraint by name instead."));
        }
    } else {
        throw new DropConstraintFailureException(schema, new NoSuchConstraintException(schema, token));
    }
}
Also used : StatementConstants(org.neo4j.kernel.api.StatementConstants) Arrays(java.util.Arrays) CreateConstraintFailureException(org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException) ThrowingIntFunction(org.neo4j.function.ThrowingIntFunction) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Status(org.neo4j.kernel.api.exceptions.Status) IndexType(org.neo4j.internal.schema.IndexType) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) NO_SUCH_LABEL(org.neo4j.kernel.api.StatementConstants.NO_SUCH_LABEL) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) DEGREES(org.neo4j.lock.ResourceTypes.DEGREES) GraphDatabaseInternalSettings.additional_lock_verification(org.neo4j.configuration.GraphDatabaseInternalSettings.additional_lock_verification) IndexWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.IndexWithNameAlreadyExistsException) ConstraintType(org.neo4j.internal.schema.ConstraintType) ConstraintWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.ConstraintWithNameAlreadyExistsException) NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) EquivalentSchemaRuleAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.EquivalentSchemaRuleAlreadyExistsException) AlreadyIndexedException(org.neo4j.kernel.api.exceptions.schema.AlreadyIndexedException) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Locks(org.neo4j.internal.kernel.api.Locks) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) RepeatedSchemaComponentException(org.neo4j.kernel.api.exceptions.schema.RepeatedSchemaComponentException) ConstraintSemantics(org.neo4j.kernel.impl.constraints.ConstraintSemantics) KernelVersion(org.neo4j.kernel.KernelVersion) ResourceType(org.neo4j.lock.ResourceType) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) KernelVersionRepository(org.neo4j.storageengine.api.KernelVersionRepository) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) StorageReader(org.neo4j.storageengine.api.StorageReader) MemoryTracker(org.neo4j.memory.MemoryTracker) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) NO_SUCH_PROPERTY_KEY(org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY) VALIDATION(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException.Phase.VALIDATION) RepeatedRelationshipTypeInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedRelationshipTypeInSchemaException) INDEX_CREATION(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext.INDEX_CREATION) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) KernelException(org.neo4j.exceptions.KernelException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) LongSet(org.eclipse.collections.api.set.primitive.LongSet) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) SchemaRule(org.neo4j.internal.schema.SchemaRule) UnableToValidateConstraintException(org.neo4j.kernel.api.exceptions.schema.UnableToValidateConstraintException) ResourceTypes(org.neo4j.lock.ResourceTypes) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ADDED_LABEL(org.neo4j.kernel.impl.newapi.IndexTxStateUpdater.LabelChangeType.ADDED_LABEL) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) RelationshipSelections(org.neo4j.internal.kernel.api.helpers.RelationshipSelections) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) Procedures(org.neo4j.internal.kernel.api.Procedures) RepeatedPropertyInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedPropertyInSchemaException) Collection(java.util.Collection) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) String.format(java.lang.String.format) NO_SUCH_NODE(org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE) List(java.util.List) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) RepeatedLabelInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedLabelInSchemaException) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) Optional(java.util.Optional) NODE(org.neo4j.common.EntityType.NODE) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ArrayUtils(org.apache.commons.lang3.ArrayUtils) DropIndexFailureException(org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) Values(org.neo4j.values.storable.Values) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) Write(org.neo4j.internal.kernel.api.Write) SchemaDescriptorImplementation(org.neo4j.internal.schema.SchemaDescriptorImplementation) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) CONSTRAINT_CREATION(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext.CONSTRAINT_CREATION) REMOVED_LABEL(org.neo4j.kernel.impl.newapi.IndexTxStateUpdater.LabelChangeType.REMOVED_LABEL) IndexConfig(org.neo4j.internal.schema.IndexConfig) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Iterator(java.util.Iterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ResourceIds.indexEntryResourceId(org.neo4j.kernel.impl.locking.ResourceIds.indexEntryResourceId) ResourceIds(org.neo4j.kernel.impl.locking.ResourceIds) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) INDEX_ENTRY(org.neo4j.lock.ResourceTypes.INDEX_ENTRY) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) IndexBelongsToConstraintException(org.neo4j.kernel.api.exceptions.schema.IndexBelongsToConstraintException) SCHEMA_NAME(org.neo4j.lock.ResourceTypes.SCHEMA_NAME) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) Token(org.neo4j.internal.kernel.api.Token) NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException)

Example 32 with SchemaDescriptor

use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.

the class IndexTxStateUpdater method onDeleteUncreated.

// PROPERTY CHANGES
/**
 * Creating an entity with its data in a transaction adds also adds that state to index transaction state (for matching indexes).
 * When deleting an entity this method will delete this state from the index transaction state.
 *
 * @param entity entity that was deleted.
 * @param propertyCursor property cursor for accessing the properties of the entity.
 * @param tokens the entity tokens this entity has.
 */
private void onDeleteUncreated(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens) {
    assert noSchemaChangedInTx();
    entity.properties(propertyCursor);
    MutableIntList propertyKeyList = IntLists.mutable.empty();
    while (propertyCursor.next()) {
        propertyKeyList.add(propertyCursor.propertyKey());
    }
    // Make sure to sort the propertyKeyIds since SchemaMatcher.onMatchingSchema requires it.
    int[] propertyKeyIds = propertyKeyList.toSortedArray();
    Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyIds, entity.entityType());
    if (!indexes.isEmpty()) {
        MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
        SchemaMatcher.onMatchingSchema(indexes.iterator(), ANY_PROPERTY_KEY, propertyKeyIds, index -> {
            MemoryTracker memoryTracker = read.txState().memoryTracker();
            SchemaDescriptor schema = index.schema();
            Value[] values = getValueTuple(entity, propertyCursor, ANY_PROPERTY_KEY, NO_VALUE, schema.getPropertyIds(), materializedProperties, memoryTracker);
            ValueTuple valueTuple = ValueTuple.of(values);
            memoryTracker.allocateHeap(valueTuple.getShallowSize());
            read.txState().indexDoUpdateEntry(schema, entity.reference(), valueTuple, null);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 33 with SchemaDescriptor

use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.

the class IndexTxStateUpdater method onPropertyChange.

private void onPropertyChange(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value beforeValue, Value afterValue) {
    assert noSchemaChangedInTx();
    Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
    if (!indexes.isEmpty()) {
        MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
        SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
            MemoryTracker memoryTracker = read.txState().memoryTracker();
            SchemaDescriptor schema = index.schema();
            int[] propertyIds = schema.getPropertyIds();
            Value[] valuesAfter = getValueTuple(entity, propertyCursor, propertyKeyId, afterValue, propertyIds, materializedProperties, memoryTracker);
            // The valuesBefore tuple is just like valuesAfter, except is has the afterValue instead of the beforeValue
            Value[] valuesBefore = Arrays.copyOf(valuesAfter, valuesAfter.length);
            int k = ArrayUtils.indexOf(propertyIds, propertyKeyId);
            valuesBefore[k] = beforeValue;
            indexingService.validateBeforeCommit(index, valuesAfter, entity.reference());
            ValueTuple valuesTupleBefore = ValueTuple.of(valuesBefore);
            ValueTuple valuesTupleAfter = ValueTuple.of(valuesAfter);
            // They are copies and same shallow size
            memoryTracker.allocateHeap(valuesTupleBefore.getShallowSize() * 2);
            read.txState().indexDoUpdateEntry(schema, entity.reference(), valuesTupleBefore, valuesTupleAfter);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 34 with SchemaDescriptor

use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.

the class IndexTxStateUpdater method onPropertyAdd.

private void onPropertyAdd(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value value) {
    assert noSchemaChangedInTx();
    Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
    if (!indexes.isEmpty()) {
        MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
        SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
            MemoryTracker memoryTracker = read.txState().memoryTracker();
            SchemaDescriptor schema = index.schema();
            Value[] values = getValueTuple(entity, propertyCursor, propertyKeyId, value, schema.getPropertyIds(), materializedProperties, memoryTracker);
            indexingService.validateBeforeCommit(index, values, entity.reference());
            ValueTuple valueTuple = ValueTuple.of(values);
            memoryTracker.allocateHeap(valueTuple.getShallowSize());
            read.txState().indexDoUpdateEntry(schema, entity.reference(), null, valueTuple);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Example 35 with SchemaDescriptor

use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.

the class IndexTxStateUpdater method onPropertyRemove.

private void onPropertyRemove(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value value) {
    assert noSchemaChangedInTx();
    Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
    if (!indexes.isEmpty()) {
        MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
        SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
            MemoryTracker memoryTracker = read.txState().memoryTracker();
            SchemaDescriptor schema = index.schema();
            Value[] values = getValueTuple(entity, propertyCursor, propertyKeyId, value, schema.getPropertyIds(), materializedProperties, memoryTracker);
            ValueTuple valueTuple = ValueTuple.of(values);
            memoryTracker.allocateHeap(valueTuple.getShallowSize());
            read.txState().indexDoUpdateEntry(schema, entity.reference(), valueTuple, null);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Aggregations

SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)58 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 Test (org.junit.jupiter.api.Test)18 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)18 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)18 Value (org.neo4j.values.storable.Value)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 ArrayList (java.util.ArrayList)6 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)6 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)5 MemoryTracker (org.neo4j.memory.MemoryTracker)5 KernelException (org.neo4j.exceptions.KernelException)4 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)4