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);
}
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;
}
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);
}
}
}
}
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();
}
}
}
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;
}
Aggregations