Search in sources :

Example 11 with TransactionFailureException

use of org.neo4j.internal.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class Operations method indexBackedConstraintCreate.

@SuppressWarnings("unchecked")
private <T extends IndexBackedConstraintDescriptor> T indexBackedConstraintCreate(T constraint, IndexPrototype prototype) throws KernelException {
    try {
        if (allStoreHolder.constraintExists(constraint)) {
            throw new AlreadyConstrainedException(constraint, CONSTRAINT_CREATION, token);
        }
        if (prototype.getIndexType() != IndexType.BTREE) {
            throw new CreateConstraintFailureException(constraint, "Cannot create backing constraint index with index type " + prototype.getIndexType() + ".");
        }
        if (prototype.schema().isFulltextSchemaDescriptor()) {
            throw new CreateConstraintFailureException(constraint, "Cannot create backing constraint index using a full-text schema: " + prototype.schema().userDescription(token));
        }
        if (prototype.schema().isRelationshipTypeSchemaDescriptor()) {
            throw new CreateConstraintFailureException(constraint, "Cannot create backing constraint index using a relationship type schema: " + prototype.schema().userDescription(token));
        }
        if (prototype.schema().isAnyTokenSchemaDescriptor()) {
            throw new CreateConstraintFailureException(constraint, "Cannot create backing constraint index using an any token schema: " + prototype.schema().userDescription(token));
        }
        if (!prototype.isUnique()) {
            throw new CreateConstraintFailureException(constraint, "Cannot create index backed constraint using an index prototype that is not unique: " + prototype.userDescription(token));
        }
        IndexDescriptor index = constraintIndexCreator.createUniquenessConstraintIndex(ktx, constraint, prototype);
        if (!allStoreHolder.constraintExists(constraint)) {
            // This looks weird, but since we release the label lock while awaiting population of the index
            // backing this constraint there can be someone else getting ahead of us, creating this exact
            // constraint
            // before we do, so now getting out here under the lock we must check again and if it exists
            // we must at this point consider this an idempotent operation because we verified earlier
            // that it didn't exist and went on to create it.
            constraint = (T) constraint.withOwnedIndexId(index.getId());
            ktx.txState().constraintDoAdd(constraint, index);
        } else {
            constraint = (T) allStoreHolder.constraintsGetForSchema(constraint.schema());
        }
        return constraint;
    } catch (UniquePropertyValueValidationException | TransactionFailureException | AlreadyConstrainedException e) {
        throw new CreateConstraintFailureException(constraint, e);
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) CreateConstraintFailureException(org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException)

Aggregations

TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)11 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)3 KernelException (org.neo4j.exceptions.KernelException)3 ConstraintViolationTransactionFailureException (org.neo4j.internal.kernel.api.exceptions.ConstraintViolationTransactionFailureException)3 CreateConstraintFailureException (org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)2 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)2 TestableTransactionAppender (org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender)2 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)2 StorageEngine (org.neo4j.storageengine.api.StorageEngine)2 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 Phaser (java.util.concurrent.Phaser)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1 BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)1