use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeRemovingIndexRuleBySchema.
@Test
void shouldAcquireSchemaWriteLockBeforeRemovingIndexRuleBySchema() throws Exception {
// given
IndexDescriptor index = IndexPrototype.forSchema(SchemaDescriptor.forLabel(0, 0)).withName("index").materialise(0);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(index);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(storageReader.indexGetForSchema(index.schema())).thenReturn(Iterators.iterator(index));
when(storageReader.indexExists(index)).thenReturn(true);
// when
operations.indexDrop(index.schema());
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, 0);
order.verify(txState).indexDoDrop(index);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnAnyTokenSchemas.
@Test
void indexedBackedConstraintCreateMustThrowOnAnyTokenSchemas() throws Exception {
// given
SchemaDescriptor schema = SchemaDescriptor.forAnyEntityTokens(NODE);
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
IndexDescriptor constraintIndex = prototype.materialise(42);
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
// when
var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
assertThat(e.getUserMessage(tokenHolders)).contains("any token schema");
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeDroppingConstraint.
@Test
void shouldAcquireSchemaWriteLockBeforeDroppingConstraint() throws Exception {
// given
UniquenessConstraintDescriptor constraint = uniqueForSchema(schema).withName("constraint");
IndexDescriptor index = IndexPrototype.uniqueForSchema(schema).withName("constraint").materialise(13);
storageReaderWithConstraints(constraint);
when(storageReader.indexExists(index)).thenReturn(true);
when(storageReader.indexGetForName("constraint")).thenReturn(index);
// when
operations.constraintDrop(constraint);
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, schema.getLabelId());
order.verify(txState).constraintDoDrop(constraint);
order.verify(txState).indexDoDrop(index);
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ, deprecatedBy = "SHOW INDEXES command")
public Stream<IndexResult> listIndexes() {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
TokenRead tokenRead = kernelTransaction.tokenRead();
IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
List<IndexResult> result = new ArrayList<>();
for (IndexDescriptor index : indexes) {
IndexResult indexResult;
indexResult = asIndexResult(tokenRead, schemaRead, index);
result.add(indexResult);
}
result.sort(Comparator.comparing(r -> r.name));
return result.stream();
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class FulltextProcedures method queryFulltextForRelationships.
@SystemProcedure
@Description("Query the given full-text index. Returns the matching relationships, and their Lucene query score, ordered by score. " + "Valid keys for the options map are: 'skip' to skip the top N results; 'limit' to limit the number of results returned.")
@Procedure(name = "db.index.fulltext.queryRelationships", mode = READ)
public Stream<RelationshipOutput> queryFulltextForRelationships(@Name("indexName") String name, @Name("queryString") String query, @Name(value = "options", defaultValue = "{}") Map<String, Object> options) throws Exception {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
IndexDescriptor indexReference = getValidIndex(name);
awaitOnline(indexReference);
EntityType entityType = indexReference.schema().entityType();
if (entityType != RELATIONSHIP) {
throw new IllegalArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for relationships.");
}
RelationshipValueIndexCursor cursor = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
IndexReadSession indexReadSession = tx.dataRead().indexReadSession(indexReference);
IndexQueryConstraints constraints = queryConstraints(options);
tx.dataRead().relationshipIndexSeek(indexReadSession, cursor, constraints, PropertyIndexQuery.fulltextSearch(query));
Spliterator<RelationshipOutput> spliterator = new SpliteratorAdaptor<>() {
@Override
public boolean tryAdvance(Consumer<? super RelationshipOutput> action) {
while (cursor.next()) {
long relationshipReference = cursor.relationshipReference();
float score = cursor.score();
RelationshipOutput relationshipOutput = RelationshipOutput.forExistingEntityOrNull(transaction, relationshipReference, score);
if (relationshipOutput != null) {
action.accept(relationshipOutput);
return true;
}
}
cursor.close();
return false;
}
};
return StreamSupport.stream(spliterator, false).onClose(cursor::close);
}
Aggregations