Search in sources :

Example 1 with RetryGremlinException

use of com.alibaba.maxgraph.compiler.exception.RetryGremlinException in project GraphScope by alibaba.

the class AbstractMixedOpProcessor method evalOpInternal.

@Override
protected void evalOpInternal(Context context, Supplier<GremlinExecutor> gremlinExecutorSupplier, AbstractEvalOpProcessor.BindingSupplier bindingsSupplier) {
    final Timer.Context timerContext = evalOpTimer.time();
    final ChannelHandlerContext ctx = context.getChannelHandlerContext();
    final RequestMessage msg = context.getRequestMessage();
    final GremlinExecutor gremlinExecutor = gremlinExecutorSupplier.get();
    final Settings settings = context.getSettings();
    final Map<String, Object> args = msg.getArgs();
    final String script = (String) args.get(Tokens.ARGS_GREMLIN);
    final String language = args.containsKey(Tokens.ARGS_LANGUAGE) ? (String) args.get(Tokens.ARGS_LANGUAGE) : null;
    final Bindings bindings = new SimpleBindings();
    // sessionless requests are always transaction managed, but in-session requests are
    // configurable.
    final boolean managedTransactionsForRequest = manageTransactions ? true : (Boolean) args.getOrDefault(Tokens.ARGS_MANAGE_TRANSACTION, false);
    // timeout override
    final long seto = args.containsKey(Tokens.ARGS_EVAL_TIMEOUT) ? Long.parseLong(args.get(Tokens.ARGS_EVAL_TIMEOUT).toString()) : settings.evaluationTimeout;
    logger.info("Receive query=>" + script);
    if (StringUtils.isEmpty(script) || StringUtils.equalsIgnoreCase(script, "''")) {
        logger.info("Finish empty query query=>" + script);
        writeResultList(context, Lists.newArrayList(), ResponseStatusCode.SUCCESS);
        return;
    }
    GremlinExecutor.LifeCycle timelyLifeCycle = createTimelyLifeCycle(timerContext, gremlinExecutor, language, bindings, script, seto, managedTransactionsForRequest, msg, context, settings, bindingsSupplier, ctx);
    CompletableFuture<Object> evalFuture = gremlinExecutor.eval(script, language, bindings, timelyLifeCycle);
    evalFuture.handle((v, t) -> {
        timerContext.stop();
        if (t != null) {
            if (t instanceof RetryGremlinException) {
                queryFromGremlin(timerContext, t, seto, managedTransactionsForRequest, msg, context, settings, bindingsSupplier, ctx, gremlinExecutor, script, language, bindings);
            } else {
                String errorMessage;
                if (t instanceof TimedInterruptTimeoutException) {
                    errorMessage = String.format("A timeout occurred within the script during" + " evaluation of [%s] - consider increasing" + " the limit given to" + " TimedInterruptCustomizerProvider", msg);
                    logger.warn(errorMessage);
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered" + " by TimedInterruptCustomizerProvider").create());
                } else if (t instanceof TimeoutException) {
                    errorMessage = String.format("Response evaluation exceeded the configured" + " threshold for request [%s] - %s", msg, t.getMessage());
                    logger.warn(errorMessage, t);
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(t.getMessage()).create());
                } else {
                    logger.warn(String.format("Exception processing a script on request [%s].", msg), t);
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_EVALUATION).statusMessage(t.getMessage()).create());
                }
            }
        }
        return null;
    });
}
Also used : GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) RetryGremlinException(com.alibaba.maxgraph.compiler.exception.RetryGremlinException) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) Timer(com.codahale.metrics.Timer) SimpleBindings(javax.script.SimpleBindings) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) Settings(org.apache.tinkerpop.gremlin.server.Settings) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with RetryGremlinException

use of com.alibaba.maxgraph.compiler.exception.RetryGremlinException in project GraphScope by alibaba.

the class MixedOpProcessor method processQueryTraversal.

private Long processQueryTraversal(String script, Object traversal, long timeout, String queryId, Stopwatch timer, RemoteRpcConnector remoteRpcConnector, RemoteRpcProcessor remoteRpcProcessor, AbstractResultProcessor nettyResultProcessor) throws RetryGremlinException {
    Pair<GraphSchema, Long> snapshotSchema;
    GraphSchema schema;
    Long totalResultNum;
    QueryStatus queryStatus;
    QueryFlowManager queryFlowManager;
    // 保证一查看到snapshotId就开始维护query_status
    synchronized (queryCallbackManager) {
        snapshotSchema = this.schemaFetcher.getSchemaSnapshotPair();
        queryStatus = queryCallbackManager.beforeExecution(snapshotSchema.getRight());
    }
    schema = snapshotSchema.getLeft();
    LogicalPlanOptimizer logicalPlanOptimizer = new LogicalPlanOptimizer(new OptimizeConfig(), this.globalPullGraphFlag, schema, snapshotSchema.getRight(), this.lambdaEnableFlag);
    queryFlowManager = (traversal instanceof GraphTraversal) ? logicalPlanOptimizer.build(GraphTraversal.class.cast(traversal)) : logicalPlanOptimizer.build(DfsTraversal.class.cast(traversal));
    boolean isLambdaExisted = TraversalHelper.anyStepRecursively(s -> s instanceof LambdaHolder, (Traversal.Admin<?, ?>) traversal);
    queryFlowManager.getQueryFlow().setScript(script).setFrontId(serverId);
    if (this.lambdaEnableFlag && isLambdaExisted) {
        queryFlowManager.getQueryFlow().setLambdaExisted(isLambdaExisted);
    }
    nettyResultProcessor.setResultTransform(new GremlinResultTransform(remoteRpcConnector, remoteRpcProcessor, this.graph, queryFlowManager.getResultValueType(), vertexCacheFlag));
    nettyResultProcessor.setLabelIndexNameList(queryFlowManager.getTreeNodeLabelManager().getUserIndexLabelList());
    nettyResultProcessor.setSchema(schema);
    try {
        TimelyQuery timelyQuery = new TimelyQuery(queryFlowManager, nettyResultProcessor, this.graph);
        Logging.query(this.graphName, com.alibaba.maxgraph.proto.RoleType.FRONTEND, this.serverId, queryId, QueryType.EXECUTE, QueryEvent.PLAN_GENERATED, timer.elapsed(TimeUnit.NANOSECONDS), null, null, script);
        timelyExecutor.execute(timelyQuery, schema, timeout, queryId);
        totalResultNum = nettyResultProcessor.total();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        queryCallbackManager.afterExecution(queryStatus);
    }
    return totalResultNum;
}
Also used : TimelyQuery(com.alibaba.maxgraph.compiler.query.TimelyQuery) DfsTraversal(com.alibaba.maxgraph.compiler.dfs.DfsTraversal) LambdaHolder(org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder) DfsTraversal(com.alibaba.maxgraph.compiler.dfs.DfsTraversal) PreparedTraversal(com.alibaba.maxgraph.compiler.prepare.PreparedTraversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) QueryFlowManager(com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager) QueryStatus(com.alibaba.maxgraph.api.query.QueryStatus) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) RetryGremlinException(com.alibaba.maxgraph.compiler.exception.RetryGremlinException) OptimizeConfig(com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig) LogicalPlanOptimizer(com.alibaba.maxgraph.compiler.optimizer.LogicalPlanOptimizer) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)

Aggregations

RetryGremlinException (com.alibaba.maxgraph.compiler.exception.RetryGremlinException)2 QueryStatus (com.alibaba.maxgraph.api.query.QueryStatus)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 DfsTraversal (com.alibaba.maxgraph.compiler.dfs.DfsTraversal)1 LogicalPlanOptimizer (com.alibaba.maxgraph.compiler.optimizer.LogicalPlanOptimizer)1 OptimizeConfig (com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig)1 QueryFlowManager (com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager)1 PreparedTraversal (com.alibaba.maxgraph.compiler.prepare.PreparedTraversal)1 TimelyQuery (com.alibaba.maxgraph.compiler.query.TimelyQuery)1 Timer (com.codahale.metrics.Timer)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 TimeoutException (java.util.concurrent.TimeoutException)1 Bindings (javax.script.Bindings)1 SimpleBindings (javax.script.SimpleBindings)1 RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)1 GremlinExecutor (org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor)1 TimedInterruptTimeoutException (org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 LambdaHolder (org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder)1