Search in sources :

Example 1 with QueryExecutionKernelException

use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.

the class TransactionHandleTest method shouldLogMessageIfCypherSyntaxErrorOccurs.

@Test
public void shouldLogMessageIfCypherSyntaxErrorOccurs() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(executionEngine.executeQuery("matsch (n) return n", map(), transactionalContext)).thenThrow(new QueryExecutionKernelException(new SyntaxException("did you mean MATCH?")));
    TransactionRegistry registry = mock(TransactionRegistry.class);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    TransactionHandle handle = new TransactionHandle(kernel, executionEngine, queryService, registry, uriScheme, false, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    Statement statement = new Statement("matsch (n) return n", map(), false, (ResultDataContent[]) null);
    handle.commit(statements(statement), output, mock(HttpServletRequest.class));
    // then
    verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).errors(argThat(hasErrors(Status.Statement.SyntaxError)));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) InOrder(org.mockito.InOrder) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) SyntaxException(org.neo4j.cypher.SyntaxException) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 2 with QueryExecutionKernelException

use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.

the class TransactionHandle method executeStatements.

private void executeStatements(StatementDeserializer statements, ExecutionResultSerializer output, List<Neo4jError> errors, HttpServletRequest request) {
    try {
        boolean hasPrevious = false;
        while (statements.hasNext()) {
            Statement statement = statements.next();
            try {
                boolean hasPeriodicCommit = engine.isPeriodicCommit(statement.statement());
                if ((statements.hasNext() || hasPrevious) && hasPeriodicCommit) {
                    throw new QueryExecutionKernelException(new InvalidSemanticsException("Cannot execute another statement after executing " + "PERIODIC COMMIT statement in the same transaction"));
                }
                if (!hasPrevious && hasPeriodicCommit) {
                    context.closeTransactionForPeriodicCommit();
                }
                hasPrevious = true;
                TransactionalContext tc = txManagerFacade.create(request, queryService, type, securityContext, statement.statement(), statement.parameters());
                Result result = safelyExecute(statement, hasPeriodicCommit, tc);
                output.statementResult(result, statement.includeStats(), statement.resultDataContents());
                output.notifications(result.getNotifications());
            } catch (KernelException | CypherException | AuthorizationViolationException | WriteOperationsNotAllowedException e) {
                errors.add(new Neo4jError(e.status(), e));
                break;
            } catch (DeadlockDetectedException e) {
                errors.add(new Neo4jError(Status.Transaction.DeadlockDetected, e));
            } catch (IOException e) {
                errors.add(new Neo4jError(Status.Network.CommunicationError, e));
                break;
            } catch (Exception e) {
                Throwable cause = e.getCause();
                if (cause instanceof Status.HasStatus) {
                    errors.add(new Neo4jError(((Status.HasStatus) cause).status(), cause));
                } else {
                    errors.add(new Neo4jError(Status.Statement.ExecutionFailed, e));
                }
                break;
            }
        }
        addToCollection(statements.errors(), errors);
    } catch (Throwable e) {
        errors.add(new Neo4jError(Status.General.UnknownError, e));
    }
}
Also used : InvalidSemanticsException(org.neo4j.cypher.InvalidSemanticsException) Status(org.neo4j.kernel.api.exceptions.Status) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IOException(java.io.IOException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) CypherException(org.neo4j.cypher.CypherException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) InvalidSemanticsException(org.neo4j.cypher.InvalidSemanticsException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Result(org.neo4j.graphdb.Result) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) CypherException(org.neo4j.cypher.CypherException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException)

Example 3 with QueryExecutionKernelException

use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.

the class TestFabricTransaction method execute.

@Override
public Result execute(String query, Map<String, Object> parameters) throws QueryExecutionException {
    var ctx = new TestFabricTransactionalContext(kernelInternalTransaction);
    var params = ValueUtils.asParameterMapValue(parameters);
    var result = new ResultSubscriber(ctx, ctx.valueMapper());
    try {
        BoltQueryExecution boltQueryExecution = fabricTransaction.executeQuery(query, params, false, result);
        result.init(boltQueryExecution.getQueryExecution());
    } catch (FabricException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        } else {
            throw new QueryExecutionException(e.getMessage(), e, e.status().code().serialize());
        }
    } catch (QueryExecutionKernelException | Neo4jException e) {
        throw new QueryExecutionException(e.getMessage(), e, e.status().code().serialize());
    }
    return result;
}
Also used : BoltQueryExecution(org.neo4j.bolt.dbapi.BoltQueryExecution) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) ResultSubscriber(org.neo4j.cypher.internal.javacompat.ResultSubscriber) FabricException(org.neo4j.fabric.executor.FabricException) Neo4jException(org.neo4j.exceptions.Neo4jException)

Example 4 with QueryExecutionKernelException

use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.

the class SnapshotExecutionEngine method executeWithRetries.

protected MaterialisedResult executeWithRetries(String query, TransactionalContext context, QueryExecutor executor) throws QueryExecutionKernelException {
    VersionContext versionContext = getCursorContext(context);
    MaterialisedResult materialisedResult;
    int attempt = 0;
    boolean dirtySnapshot;
    do {
        if (attempt == maxQueryExecutionAttempts) {
            throw new QueryExecutionKernelException(new UnstableSnapshotException("Unable to get clean data snapshot for query '%s' after %d attempts.", query, attempt));
        }
        if (attempt > 0) {
            context.executingQuery().onRetryAttempted();
        }
        attempt++;
        versionContext.initRead();
        materialisedResult = new MaterialisedResult();
        QueryExecution queryExecution = executor.execute(materialisedResult);
        materialisedResult.consumeAll(queryExecution);
        // objects is guaranteed by schema and not by execution engine
        if (context.transaction().kernelTransaction().isSchemaTransaction()) {
            return materialisedResult;
        }
        dirtySnapshot = versionContext.isDirty();
        if (isUnstableSnapshot(materialisedResult, dirtySnapshot)) {
            throw new QueryExecutionKernelException(new UnstableSnapshotException("Unable to get clean data snapshot for query '%s' that performs updates.", query, attempt));
        }
    } while (dirtySnapshot);
    return materialisedResult;
}
Also used : VersionContext(org.neo4j.io.pagecache.context.VersionContext) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution)

Example 5 with QueryExecutionKernelException

use of org.neo4j.kernel.impl.query.QueryExecutionKernelException in project neo4j by neo4j.

the class SnapshotExecutionEngine method executeQuery.

@Override
public Result executeQuery(String query, MapValue parameters, TransactionalContext context, boolean prePopulate) throws QueryExecutionKernelException {
    QueryExecutor queryExecutor = querySubscriber -> super.executeQuery(query, parameters, context, prePopulate, querySubscriber);
    ResultSubscriber resultSubscriber = new ResultSubscriber(context);
    MaterialisedResult materialisedResult = executeWithRetries(query, context, queryExecutor);
    QueryExecution queryExecution = materialisedResult.stream(resultSubscriber);
    resultSubscriber.init(queryExecution);
    return resultSubscriber;
}
Also used : VersionContext(org.neo4j.io.pagecache.context.VersionContext) FullyParsedQuery(org.neo4j.cypher.internal.FullyParsedQuery) Result(org.neo4j.graphdb.Result) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) LogProvider(org.neo4j.logging.LogProvider) Config(org.neo4j.configuration.Config) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) QueryExecutionMonitor(org.neo4j.kernel.impl.query.QueryExecutionMonitor) CompilerFactory(org.neo4j.cypher.internal.CompilerFactory) InputDataStream(org.neo4j.cypher.internal.runtime.InputDataStream) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) QuerySubscriber(org.neo4j.kernel.impl.query.QuerySubscriber) MapValue(org.neo4j.values.virtual.MapValue) CaffeineCacheFactory(org.neo4j.cypher.internal.cache.CaffeineCacheFactory) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution)

Aggregations

QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)13 Result (org.neo4j.graphdb.Result)5 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)5 Test (org.junit.jupiter.api.Test)4 VersionContext (org.neo4j.io.pagecache.context.VersionContext)2 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)2 IOException (java.io.IOException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 BoltQueryExecution (org.neo4j.bolt.dbapi.BoltQueryExecution)1 BoltResultHandle (org.neo4j.bolt.v1.runtime.TransactionStateMachine.BoltResultHandle)1 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)1 Config (org.neo4j.configuration.Config)1 GraphDatabaseInternalSettings (org.neo4j.configuration.GraphDatabaseInternalSettings)1 CypherException (org.neo4j.cypher.CypherException)1 InvalidSemanticsException (org.neo4j.cypher.InvalidSemanticsException)1 SyntaxException (org.neo4j.cypher.SyntaxException)1