use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class Operations method enforceNodeKeyConstraint.
private void enforceNodeKeyConstraint(SchemaDescriptor schema) throws KernelException {
IndexDescriptor index = allStoreHolder.findUsableTokenIndex(NODE);
if (index != IndexDescriptor.NO_INDEX) {
try (var cursor = cursors.allocateFullAccessNodeLabelIndexCursor(ktx.cursorContext())) {
var session = allStoreHolder.tokenReadSession(index);
allStoreHolder.nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(schema.getLabelId()));
constraintSemantics.validateNodeKeyConstraint(cursor, nodeCursor, propertyCursor, schema.asLabelSchemaDescriptor(), token);
}
} else {
try (var cursor = cursors.allocateFullAccessNodeCursor(ktx.cursorContext())) {
allStoreHolder.allNodesScan(cursor);
constraintSemantics.validateNodeKeyConstraint(new FilteringNodeCursorWrapper(cursor, CursorPredicates.hasLabel(schema.getLabelId())), propertyCursor, schema.asLabelSchemaDescriptor(), token);
}
}
}
use of org.neo4j.internal.schema.IndexDescriptor 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);
}
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class Operations method constraintDrop.
@Override
public void constraintDrop(ConstraintDescriptor constraint) throws SchemaKernelException {
// Lock
SchemaDescriptor schema = constraint.schema();
exclusiveLock(schema.keyType(), schema.lockingKeys());
exclusiveSchemaNameLock(constraint.getName());
ktx.assertOpen();
// verify data integrity
try {
assertConstraintExists(constraint);
} catch (NoSuchConstraintException e) {
throw new DropConstraintFailureException(constraint, e);
}
// Drop it like it's hot
TransactionState txState = ktx.txState();
txState.constraintDoDrop(constraint);
if (constraint.enforcesUniqueness()) {
IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
if (index != IndexDescriptor.NO_INDEX) {
txState.indexDoDrop(index);
}
}
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class Read method nodeLabelScan.
@Override
public final Scan<NodeLabelIndexCursor> nodeLabelScan(int label) {
ktx.assertOpen();
CursorContext cursorContext = ktx.cursorContext();
TokenScan tokenScan;
try {
Iterator<IndexDescriptor> index = index(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE));
if (!index.hasNext()) {
throw new IndexNotFoundKernelException("There is no index that can back a node label scan.");
}
IndexDescriptor nliDescriptor = index.next();
DefaultTokenReadSession session = (DefaultTokenReadSession) tokenReadSession(nliDescriptor);
tokenScan = session.reader.entityTokenScan(label, cursorContext);
} catch (IndexNotFoundKernelException e) {
throw new RuntimeException(e);
}
return new NodeLabelIndexCursorScan(this, label, tokenScan, cursorContext);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class OnlineIndexUpdates method eagerlyGatherTokenIndexUpdates.
private void eagerlyGatherTokenIndexUpdates(EntityUpdates entityUpdates, EntityType entityType, long txId) {
IndexDescriptor relatedToken = schemaCache.getTokenIndex(entityType);
entityUpdates.tokenUpdateForIndexKey(relatedToken, txId).ifPresent(updates::add);
}
Aggregations