use of org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.
private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
try {
NewIndexDescriptor index = constraint.ownedIndexDescriptor();
assertIndexOnline(state, index);
int labelId = index.schema().getLabelId();
state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
if (existing != NO_SUCH_NODE && existing != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e);
}
}
use of org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException in project neo4j by neo4j.
the class Operations method validateNoExistingNodeWithExactValues.
/**
* Check so that there is not an existing node with the exact match of label and property
*/
private void validateNoExistingNodeWithExactValues(IndexBackedConstraintDescriptor constraint, PropertyIndexQuery.ExactPredicate[] propertyValues, long modifiedNode) throws UniquePropertyValueValidationException, UnableToValidateConstraintException {
IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
try (FullAccessNodeValueIndexCursor valueCursor = cursors.allocateFullAccessNodeValueIndexCursor(ktx.cursorContext(), memoryTracker);
IndexReaders indexReaders = new IndexReaders(index, allStoreHolder)) {
assertIndexOnline(index);
SchemaDescriptor schema = index.schema();
long[] labelIds = schema.lockingKeys();
if (labelIds.length != 1) {
throw new UnableToValidateConstraintException(constraint, new AssertionError(format("Constraint indexes are not expected to be multi-token indexes, " + "but the constraint %s was referencing an index with the following schema: %s.", constraint.userDescription(token), schema.userDescription(token))), token);
}
// Take a big fat lock, and check for existing node in index
ktx.lockClient().acquireExclusive(ktx.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelIds[0], propertyValues));
allStoreHolder.nodeIndexSeekWithFreshIndexReader(valueCursor, indexReaders.createReader(), propertyValues);
if (valueCursor.next() && valueCursor.nodeReference() != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(valueCursor.nodeReference(), NO_SUCH_NODE, PropertyIndexQuery.asValueTuple(propertyValues)), token);
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e, token);
}
}
Aggregations