Search in sources :

Example 26 with KernelException

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

the class TransactionImpl method relationshipsByTypeAndProperty.

private ResourceIterator<Relationship> relationshipsByTypeAndProperty(KernelTransaction transaction, int typeId, PropertyIndexQuery query) {
    Read read = transaction.dataRead();
    if (query.propertyKeyId() == TokenRead.NO_TOKEN || typeId == TokenRead.NO_TOKEN) {
        return emptyResourceIterator();
    }
    var index = findUsableMatchingIndex(transaction, SchemaDescriptor.forRelType(typeId, query.propertyKeyId()));
    if (index != IndexDescriptor.NO_INDEX) {
        // Ha! We found an index - let's use it to find matching relationships
        try {
            var cursor = transaction.cursors().allocateRelationshipValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker());
            IndexReadSession indexSession = read.indexReadSession(index);
            read.relationshipIndexSeek(indexSession, cursor, unconstrained(), query);
            return new CursorIterator<>(cursor, RelationshipIndexCursor::relationshipReference, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // weird at this point but ignore and fallback to a type scan
        }
    }
    return getRelationshipsByTypeAndPropertyWithoutPropertyIndex(transaction, typeId, query);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException) RelationshipIndexCursor(org.neo4j.internal.kernel.api.RelationshipIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 27 with KernelException

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

the class TransactionImpl method getRelationshipsByTypeAndPropertyWithoutPropertyIndex.

private ResourceIterator<Relationship> getRelationshipsByTypeAndPropertyWithoutPropertyIndex(KernelTransaction ktx, int typeId, PropertyIndexQuery... queries) {
    var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.RELATIONSHIP));
    if (index != IndexDescriptor.NO_INDEX) {
        try {
            var session = ktx.dataRead().tokenReadSession(index);
            var cursor = ktx.cursors().allocateRelationshipTypeIndexCursor(ktx.cursorContext());
            ktx.dataRead().relationshipTypeScan(session, cursor, unconstrained(), new TokenPredicate(typeId));
            var relationshipScanCursor = ktx.cursors().allocateRelationshipScanCursor(ktx.cursorContext());
            var propertyCursor = ktx.cursors().allocatePropertyCursor(ktx.cursorContext(), ktx.memoryTracker());
            return new RelationshipTypePropertyIterator(ktx.dataRead(), cursor, relationshipScanCursor, propertyCursor, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker, queries);
        } catch (KernelException e) {
        // ignore, fallback to all node scan
        }
    }
    return getRelationshipsByTypeAndPropertyViaAllRelsScan(ktx, typeId, queries);
}
Also used : RelationshipTypePropertyIterator(org.neo4j.kernel.impl.coreapi.internal.RelationshipTypePropertyIterator) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 28 with KernelException

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

the class TransactionImpl method createNode.

@Override
public Node createNode(Label... labels) {
    var ktx = kernelTransaction();
    try {
        TokenWrite tokenWrite = ktx.tokenWrite();
        int[] labelIds = new int[labels.length];
        String[] labelNames = new String[labels.length];
        for (int i = 0; i < labelNames.length; i++) {
            labelNames[i] = labels[i].name();
        }
        tokenWrite.labelGetOrCreateForNames(labelNames, labelIds);
        Write write = ktx.dataWrite();
        long nodeId = write.nodeCreateWithLabels(labelIds);
        return newNodeEntity(nodeId);
    } catch (ConstraintValidationException e) {
        throw new ConstraintViolationException("Unable to add label.", e);
    } catch (SchemaKernelException e) {
        throw new IllegalArgumentException(e);
    } catch (KernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 29 with KernelException

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

the class TransactionImpl method allRelationshipsWithType.

private ResourceIterator<Relationship> allRelationshipsWithType(final RelationshipType type) {
    KernelTransaction ktx = kernelTransaction();
    int typeId = ktx.tokenRead().relationshipType(type.name());
    if (typeId == TokenRead.NO_TOKEN) {
        return emptyResourceIterator();
    }
    var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.RELATIONSHIP));
    if (index != IndexDescriptor.NO_INDEX) {
        try {
            var session = ktx.dataRead().tokenReadSession(index);
            var cursor = ktx.cursors().allocateRelationshipTypeIndexCursor(ktx.cursorContext());
            ktx.dataRead().relationshipTypeScan(session, cursor, unconstrained(), new TokenPredicate(typeId));
            return new CursorIterator<>(cursor, RelationshipIndexCursor::relationshipReference, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // ignore, fallback to all node scan
        }
    }
    return allRelationshipsByTypeWithoutIndex(ktx, typeId);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException) RelationshipIndexCursor(org.neo4j.internal.kernel.api.RelationshipIndexCursor)

Example 30 with KernelException

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

the class TransactionImpl method relationshipsByTypeAndProperties.

private ResourceIterator<Relationship> relationshipsByTypeAndProperties(KernelTransaction tx, int typeId, PropertyIndexQuery.ExactPredicate... queries) {
    Read read = tx.dataRead();
    if (isInvalidQuery(typeId, queries)) {
        return emptyResourceIterator();
    }
    int[] propertyIds = getPropertyIds(queries);
    IndexDescriptor index = findUsableMatchingCompositeIndex(tx, SchemaDescriptor.forRelType(typeId, propertyIds), propertyIds, () -> tx.schemaRead().indexesGetForRelationshipType(typeId));
    if (index != IndexDescriptor.NO_INDEX) {
        try {
            RelationshipValueIndexCursor cursor = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
            IndexReadSession indexSession = read.indexReadSession(index);
            read.relationshipIndexSeek(indexSession, cursor, unconstrained(), getReorderedIndexQueries(index.schema().getPropertyIds(), queries));
            return new CursorIterator<>(cursor, RelationshipIndexCursor::relationshipReference, c -> newRelationshipEntity(c.relationshipReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // weird at this point but ignore and fallback to a label scan
        }
    }
    return getRelationshipsByTypeAndPropertyWithoutPropertyIndex(tx, typeId, queries);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException) RelationshipIndexCursor(org.neo4j.internal.kernel.api.RelationshipIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

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