Search in sources :

Example 1 with SchemaRuleNotFoundException

use of org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException in project neo4j by neo4j.

the class OperationsFacade method uniqueIndexGetForLabelAndPropertyKey.

@Override
public NewIndexDescriptor uniqueIndexGetForLabelAndPropertyKey(NodePropertyDescriptor descriptor) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
    NewIndexDescriptor result = null;
    Iterator<NewIndexDescriptor> indexes = uniqueIndexesGetForLabel(descriptor.getLabelId());
    while (indexes.hasNext()) {
        NewIndexDescriptor index = indexes.next();
        if (index.schema().equals(SchemaBoundary.map(descriptor))) {
            if (null == result) {
                result = index;
            } else {
                throw new DuplicateSchemaRuleException(SchemaRule.Kind.CONSTRAINT_INDEX_RULE, index.schema());
            }
        }
    }
    if (null == result) {
        throw new SchemaRuleNotFoundException(SchemaRule.Kind.CONSTRAINT_INDEX_RULE, SchemaBoundary.map(descriptor));
    }
    return result;
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) DuplicateSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)

Example 2 with SchemaRuleNotFoundException

use of org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException in project neo4j by neo4j.

the class SchemaStorage method constraintsGetSingle.

/**
     * Get the constraint rule that matches the given ConstraintDescriptor
     * @param descriptor the ConstraintDescriptor to match
     * @return the matching ConstrainRule
     * @throws SchemaRuleNotFoundException if no ConstraintRule matches the given descriptor
     * @throws DuplicateSchemaRuleException if two or more ConstraintRules match the given descriptor
     */
public ConstraintRule constraintsGetSingle(final ConstraintDescriptor descriptor) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
    Iterator<ConstraintRule> rules = loadAllSchemaRules(descriptor::isSame, ConstraintRule.class, false);
    if (!rules.hasNext()) {
        throw new SchemaRuleNotFoundException(SchemaRule.Kind.map(descriptor), descriptor.schema());
    }
    ConstraintRule rule = rules.next();
    if (rules.hasNext()) {
        throw new DuplicateSchemaRuleException(SchemaRule.Kind.map(descriptor), descriptor.schema());
    }
    return rule;
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) DuplicateSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)

Example 3 with SchemaRuleNotFoundException

use of org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException in project neo4j by neo4j.

the class OperationsFacade method indexGetForLabelAndPropertyKey.

// </DataReadCursors>
// <SchemaRead>
@Override
public NewIndexDescriptor indexGetForLabelAndPropertyKey(NodePropertyDescriptor descriptor) throws SchemaRuleNotFoundException {
    statement.assertOpen();
    NewIndexDescriptor indexDescriptor = schemaRead().indexGetForLabelAndPropertyKey(statement, descriptor);
    if (indexDescriptor == null) {
        throw new SchemaRuleNotFoundException(SchemaRule.Kind.INDEX_RULE, SchemaBoundary.map(descriptor));
    }
    return indexDescriptor;
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)

Example 4 with SchemaRuleNotFoundException

use of org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException in project neo4j by neo4j.

the class ConstraintIndexCreator method createUniquenessConstraintIndex.

/**
     * You MUST hold a schema write lock before you call this method.
     * However the schema write lock is temporarily released while populating the index backing the constraint.
     * It goes a little like this:
     * <ol>
     * <li>Prerequisite: Getting here means that there's an open schema transaction which has acquired the
     * SCHEMA WRITE lock.</li>
     * <li>Index schema rule which is backing the constraint is created in a nested mini-transaction
     * which doesn't acquire any locking, merely adds tx state and commits so that the index rule is applied
     * to the store, which triggers the index population</li>
     * <li>Release the SCHEMA WRITE lock</li>
     * <li>Await index population to complete</li>
     * <li>Acquire the SCHEMA WRITE lock (effectively blocking concurrent transactions changing
     * data related to this constraint, and it so happens, most other transactions as well) and verify
     * the uniqueness of the built index</li>
     * <li>Leave this method, knowing that the uniqueness constraint rule will be added to tx state
     * and this tx committed, which will create the uniqueness constraint</li>
     * </ol>
     */
public long createUniquenessConstraintIndex(KernelStatement state, SchemaReadOperations schema, LabelSchemaDescriptor descriptor) throws TransactionFailureException, CreateConstraintFailureException, DropIndexFailureException, UniquePropertyValueValidationException {
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    NewIndexDescriptor index = createConstraintIndex(descriptor);
    boolean success = false;
    boolean reacquiredSchemaLock = false;
    Client locks = state.locks().pessimistic();
    try {
        long indexId = schema.indexGetCommittedId(state, index);
        // Release the SCHEMA WRITE lock during index population.
        // At this point the integrity of the constraint to be created was checked
        // while holding the lock and the index rule backing the soon-to-be-created constraint
        // has been created. Now it's just the population left, which can take a long time
        releaseSchemaLock(locks);
        awaitConstrainIndexPopulation(constraint, indexId);
        // Index population was successful, but at this point we don't know if the uniqueness constraint holds.
        // Acquire SCHEMA WRITE lock and verify the constraints here in this user transaction
        // and if everything checks out then it will be held until after the constraint has been
        // created and activated.
        acquireSchemaLock(state, locks);
        reacquiredSchemaLock = true;
        indexingService.getIndexProxy(indexId).verifyDeferredConstraints(propertyAccessor);
        success = true;
        return indexId;
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new IllegalStateException(String.format("Index (%s) that we just created does not exist.", descriptor));
    } catch (IndexEntryConflictException e) {
        throw new UniquePropertyValueValidationException(constraint, VERIFICATION, e);
    } catch (InterruptedException | IOException e) {
        throw new CreateConstraintFailureException(constraint, e);
    } finally {
        if (!success) {
            if (!reacquiredSchemaLock) {
                acquireSchemaLock(state, locks);
            }
            dropUniquenessConstraintIndex(index);
        }
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IOException(java.io.IOException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Client(org.neo4j.kernel.impl.locking.Locks.Client) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)

Example 5 with SchemaRuleNotFoundException

use of org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException in project neo4j by neo4j.

the class AwaitIndexProcedureTest method shouldThrowAnExceptionIfTheIndexDoesNotExist.

@Test
public void shouldThrowAnExceptionIfTheIndexDoesNotExist() throws SchemaRuleNotFoundException, IndexNotFoundKernelException {
    when(operations.propertyKeyGetForName(anyString())).thenReturn(0);
    when(operations.labelGetForName(anyString())).thenReturn(0);
    when(operations.indexGetForLabelAndPropertyKey(any())).thenThrow(new SchemaRuleNotFoundException(INDEX_RULE, SchemaDescriptorFactory.forLabel(0, 0)));
    try {
        procedure.awaitIndex(":Person(name)", timeout, timeoutUnits);
        fail("Expected an exception");
    } catch (ProcedureException e) {
        assertThat(e.status(), is(Status.Schema.IndexNotFound));
    }
}
Also used : SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Aggregations

SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)6 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 Test (org.junit.Test)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2 DuplicateSchemaRuleException (org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)2 IOException (java.io.IOException)1 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)1 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)1 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)1 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)1 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)1 Client (org.neo4j.kernel.impl.locking.Locks.Client)1 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)1