Search in sources :

Example 1 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class WriteTestSupport method setup.

@Override
public void setup(Path storeDir, Consumer<GraphDatabaseService> sysCreate) {
    TestDatabaseManagementServiceBuilder databaseManagementServiceBuilder = newManagementServiceBuilder(storeDir);
    managementService = configure(databaseManagementServiceBuilder).build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try (KernelTransaction tx = beginTransaction()) {
        // We are creating these dummy tokens so that that the ones that we actually use don't get
        // the value 0. Using 0 may hide bugs that are caused by default the initialization of ints
        TokenWrite tokenWrite = tx.tokenWrite();
        tokenWrite.propertyKeyCreateForName("DO_NOT_USE", false);
        tokenWrite.labelCreateForName("DO_NOT_USE", false);
        tokenWrite.relationshipTypeCreateForName("DO_NOT_USE", false);
    } catch (KernelException e) {
        throw new AssertionError("Failed to setup database", e);
    }
    GraphDatabaseService sysDb = managementService.database(SYSTEM_DATABASE_NAME);
    sysCreate.accept(sysDb);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) KernelException(org.neo4j.exceptions.KernelException)

Example 2 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class Operations method uniquePropertyConstraintCreate.

@Override
public ConstraintDescriptor uniquePropertyConstraintCreate(IndexPrototype prototype) throws KernelException {
    SchemaDescriptor schema = prototype.schema();
    exclusiveSchemaLock(schema);
    ktx.assertOpen();
    prototype = ensureIndexPrototypeHasIndexProvider(prototype);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
    try {
        assertValidDescriptor(schema, SchemaKernelException.OperationContext.CONSTRAINT_CREATION);
        if (prototype.getName().isEmpty()) {
            constraint = ensureConstraintHasName(constraint);
            prototype = prototype.withName(constraint.getName());
        } else {
            constraint = constraint.withName(prototype.getName().get());
        }
        exclusiveSchemaNameLock(constraint.getName());
        assertNoBlockingSchemaRulesExists(constraint);
    } catch (KernelException e) {
        // Try not to hold on to exclusive schema locks when we don't strictly need them.
        exclusiveSchemaUnlock(schema);
        throw e;
    }
    // Create constraints
    constraint = indexBackedConstraintCreate(constraint, prototype);
    return constraint;
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 3 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class IntegrityValidator method validateSchemaRule.

void validateSchemaRule(SchemaRule schemaRule) throws TransactionFailureException {
    Preconditions.checkState(indexValidator != null, "No index validator installed");
    KernelVersion currentVersion = neoStores.getMetaDataStore().kernelVersion();
    if (currentVersion.isLessThan(VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
        if (schemaRule instanceof IndexDescriptor) {
            IndexDescriptor index = (IndexDescriptor) schemaRule;
            if (index.isTokenIndex() || isBtreeRelationshipPropertyIndex(index)) {
                throw new TransactionFailureException(Status.General.UpgradeRequired, "Index operation on index '%s' not allowed. " + "Required kernel version for this transaction is %s, but actual version was %s.", index, VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED.name(), currentVersion.name());
            }
        }
    }
    if (schemaRule instanceof ConstraintDescriptor) {
        ConstraintDescriptor constraint = (ConstraintDescriptor) schemaRule;
        if (constraint.isIndexBackedConstraint()) {
            long ownedIndex = constraint.asIndexBackedConstraint().ownedIndexId();
            try {
                indexValidator.validateIndex(ownedIndex);
            } catch (KernelException e) {
                // and have recovery performed. It's the safest bet to avoid loosing data.
                throw new TransactionFailureException(Status.Transaction.TransactionValidationFailed, e, "Index validation of " + schemaRule + " failed, specifically for its owned index " + ownedIndex, e);
            }
        }
    }
}
Also used : KernelVersion(org.neo4j.kernel.KernelVersion) ConstraintViolationTransactionFailureException(org.neo4j.internal.kernel.api.exceptions.ConstraintViolationTransactionFailureException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) KernelException(org.neo4j.exceptions.KernelException)

Example 4 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class KernelTransactionImplementation method closeTransaction.

@Override
public long closeTransaction() throws TransactionFailureException {
    assertTransactionOpen();
    assertTransactionNotClosing();
    closing = true;
    try {
        if (failure || !success || isTerminated()) {
            rollback(null);
            failOnNonExplicitRollbackIfNeeded();
            return ROLLBACK_ID;
        } else {
            return commitTransaction();
        }
    } catch (TransactionFailureException e) {
        throw e;
    } catch (KernelException e) {
        throw new TransactionFailureException(e.status(), e, "Unexpected kernel exception");
    } finally {
        try {
            closed = true;
            closing = false;
            transactionEvent.setSuccess(success);
            transactionEvent.setFailure(failure);
            transactionEvent.setTransactionWriteState(writeState.name());
            transactionEvent.setReadOnly(txState == null || !txState.hasChanges());
            transactionEvent.close();
        } finally {
            release();
        }
    }
}
Also used : TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) ConstraintViolationTransactionFailureException(org.neo4j.internal.kernel.api.exceptions.ConstraintViolationTransactionFailureException) KernelException(org.neo4j.exceptions.KernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)

Example 5 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class DropConstraintFailureException method getUserMessage.

@Override
public String getUserMessage(TokenNameLookup tokenNameLookup) {
    String message;
    if (constraint instanceof SchemaDescriptorSupplier) {
        SchemaDescriptorSupplier schemaish = (SchemaDescriptorSupplier) constraint;
        message = "Unable to drop constraint on " + schemaish.userDescription(tokenNameLookup) + ": ";
    } else if (constraint instanceof String) {
        String name = (String) constraint;
        message = "Unable to drop constraint `" + name + "`: ";
    } else {
        return getMessage();
    }
    Throwable cause = getCause();
    if (cause instanceof KernelException) {
        KernelException exception = (KernelException) cause;
        message += exception.getUserMessage(tokenNameLookup);
    } else {
        message += cause.getMessage();
    }
    return message;
}
Also used : SchemaDescriptorSupplier(org.neo4j.internal.schema.SchemaDescriptorSupplier) KernelException(org.neo4j.exceptions.KernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)

Aggregations

KernelException (org.neo4j.exceptions.KernelException)58 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)22 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)21 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)15 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)13 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)12 Test (org.junit.jupiter.api.Test)11 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)10 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)10 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)10 List (java.util.List)8 NotFoundException (org.neo4j.graphdb.NotFoundException)8 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)8 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)7 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)7 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)7 ArrayList (java.util.ArrayList)6