Search in sources :

Example 21 with KernelException

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

the class FullCheckIntegrationTest method createIndexRule.

private void createIndexRule(final int labelId, final int... propertyKeyIds) throws Exception {
    AtomicReference<String> indexName = new AtomicReference<>();
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) throws KernelException {
            int id = (int) next.schema();
            String name = "index_" + id;
            IndexDescriptor index = forSchema(forLabel(labelId, propertyKeyIds), DESCRIPTOR).withName(name).materialise(id);
            indexName.set(name);
            index = tx.completeConfiguration(index);
            SchemaRecord before = new SchemaRecord(id);
            SchemaRecord after = cloneRecord(before);
            serializeRule(index, after, tx, next);
            tx.createSchema(before, after, index);
        }
    });
    fixture.apply(tx -> {
        try {
            tx.schema().awaitIndexOnline(indexName.get(), 1, TimeUnit.MINUTES);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof KernelException) {
            // this is OK since many createIndex calls will create invalid indexes
            } else {
                throw e;
            }
        }
    });
}
Also used : TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) AtomicReference(java.util.concurrent.atomic.AtomicReference) KernelException(org.neo4j.exceptions.KernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture)

Example 22 with KernelException

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

the class RecordStorageEngineTest method databasePanicIsRaisedWhenTxApplicationFails.

@Test
void databasePanicIsRaisedWhenTxApplicationFails() throws Throwable {
    RecordStorageEngine engine = buildRecordStorageEngine();
    Exception applicationError = executeFailingTransaction(engine);
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(databaseHealth).panic(captor.capture());
    Throwable exception = captor.getValue();
    if (exception instanceof KernelException) {
        assertThat(((KernelException) exception).status()).isEqualTo(Status.General.UnknownError);
        exception = exception.getCause();
    }
    assertThat(exception).isEqualTo(applicationError);
}
Also used : KernelException(org.neo4j.exceptions.KernelException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) IOException(java.io.IOException) KernelException(org.neo4j.exceptions.KernelException) Test(org.junit.jupiter.api.Test)

Example 23 with KernelException

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

the class EntityTest method mockedTransactionWithDepletedTokens.

InternalTransaction mockedTransactionWithDepletedTokens() throws KernelException {
    var internalTransaction = mock(InternalTransaction.class);
    var ktx = mock(KernelTransaction.class);
    var tokenWrite = mock(TokenWrite.class);
    when(ktx.tokenWrite()).thenReturn(tokenWrite);
    when(tokenWrite.labelGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_LABEL));
    when(tokenWrite.propertyKeyGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_PROPERTY_KEY));
    when(tokenWrite.relationshipTypeGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_RELATIONSHIP_TYPE));
    when(internalTransaction.kernelTransaction()).thenReturn(ktx);
    return internalTransaction;
}
Also used : TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) KernelException(org.neo4j.exceptions.KernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)

Example 24 with KernelException

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

the class AllStoreHolder method countsForRelationshipWithoutTxState.

@Override
public long countsForRelationshipWithoutTxState(int startLabelId, int typeId, int endLabelId) {
    AccessMode mode = ktx.securityContext().mode();
    CursorContext cursorContext = ktx.cursorContext();
    if (mode.allowsTraverseRelType(typeId) && mode.allowsTraverseNode(startLabelId) && mode.allowsTraverseNode(endLabelId)) {
        return storageReader.countsForRelationship(startLabelId, typeId, endLabelId, cursorContext);
    }
    if (mode.disallowsTraverseRelType(typeId) || mode.disallowsTraverseLabel(startLabelId) || mode.disallowsTraverseLabel(endLabelId)) {
        // so the count will be 0.
        return 0;
    }
    // token index scan can only scan for single relationship type
    if (typeId != TokenRead.ANY_RELATIONSHIP_TYPE) {
        try {
            var index = findUsableTokenIndex(EntityType.RELATIONSHIP);
            if (index != IndexDescriptor.NO_INDEX) {
                long count = 0;
                try (DefaultRelationshipTypeIndexCursor relationshipsWithType = cursors.allocateRelationshipTypeIndexCursor(cursorContext);
                    DefaultRelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(cursorContext);
                    DefaultNodeCursor sourceNode = cursors.allocateNodeCursor(cursorContext);
                    DefaultNodeCursor targetNode = cursors.allocateNodeCursor(cursorContext)) {
                    var session = tokenReadSession(index);
                    this.relationshipTypeScan(session, relationshipsWithType, unconstrained(), new TokenPredicate(typeId));
                    while (relationshipsWithType.next()) {
                        relationshipsWithType.relationship(relationship);
                        count += countRelationshipsWithEndLabels(relationship, sourceNode, targetNode, startLabelId, endLabelId);
                    }
                }
                return count - countsForRelationshipInTxState(startLabelId, typeId, endLabelId);
            }
        } catch (KernelException ignored) {
        // ignore, fallback to allRelationshipsScan
        }
    }
    long count;
    try (DefaultRelationshipScanCursor rels = cursors.allocateRelationshipScanCursor(cursorContext);
        DefaultNodeCursor sourceNode = cursors.allocateFullAccessNodeCursor(cursorContext);
        DefaultNodeCursor targetNode = cursors.allocateFullAccessNodeCursor(cursorContext)) {
        this.allRelationshipsScan(rels);
        Predicate<RelationshipScanCursor> predicate = typeId == TokenRead.ANY_RELATIONSHIP_TYPE ? alwaysTrue() : CursorPredicates.hasType(typeId);
        var filteredCursor = new FilteringRelationshipScanCursorWrapper(rels, predicate);
        count = countRelationshipsWithEndLabels(filteredCursor, sourceNode, targetNode, startLabelId, endLabelId);
    }
    return count - countsForRelationshipInTxState(startLabelId, typeId, endLabelId);
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) AdminAccessMode(org.neo4j.internal.kernel.api.security.AdminAccessMode) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) OverriddenAccessMode(org.neo4j.kernel.impl.api.security.OverriddenAccessMode) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 25 with KernelException

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

the class TokenTestBase method assertIllegalToken.

private void assertIllegalToken(ThrowingConsumer<Token, KernelException> f) {
    try (KernelTransaction tx = beginTransaction()) {
        f.accept(tx.token());
        fail("Expected IllegalTokenNameException");
    } catch (IllegalTokenNameException e) {
    // wanted
    } catch (KernelException e) {
        fail("Unwanted exception: " + e.getMessage());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) KernelException(org.neo4j.exceptions.KernelException)

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