Search in sources :

Example 1 with QueryStatus

use of com.alibaba.maxgraph.api.query.QueryStatus in project GraphScope by alibaba.

the class ReadOnlyMaxGraphProcessorLoader method loadProcessor.

@Override
public void loadProcessor(Settings settings) {
    OpLoader.init(settings);
    QueryCallbackManager queryCallbackManager = new QueryCallbackManager() {

        @Override
        public QueryStatus beforeExecution(Long snapshotId) {
            return null;
        }

        @Override
        public void afterExecution(QueryStatus query) {
        }
    };
    MixedOpProcessor mixedOpProcessor = new MixedOpProcessor(this.graph, this.instanceConfig, this.rpcAddressFetcher, this.schemaFetcher, null, null, queryCallbackManager);
    mixedOpProcessor.init(settings);
    MaxGraphOpLoader.addOpProcessor(mixedOpProcessor.getName(), mixedOpProcessor);
    MixedTraversalOpProcessor mixedTraversalOpProcessor = new MixedTraversalOpProcessor(this.graph, this.instanceConfig, this.rpcAddressFetcher, this.schemaFetcher, null, queryCallbackManager);
    mixedTraversalOpProcessor.init(settings);
    MaxGraphOpLoader.addOpProcessor(mixedTraversalOpProcessor.getName(), mixedTraversalOpProcessor);
}
Also used : MixedTraversalOpProcessor(com.alibaba.maxgraph.server.processor.MixedTraversalOpProcessor) MixedOpProcessor(com.alibaba.maxgraph.server.processor.MixedOpProcessor) QueryCallbackManager(com.alibaba.maxgraph.api.query.QueryCallbackManager) QueryStatus(com.alibaba.maxgraph.api.query.QueryStatus)

Example 2 with QueryStatus

use of com.alibaba.maxgraph.api.query.QueryStatus in project GraphScope by alibaba.

the class MixedTraversalOpProcessor method doProcessTraversal.

private Long doProcessTraversal(Context context, Object object, Graph graph, long timeout, String queryId, Stopwatch timer) {
    Pair<GraphSchema, Long> snapshotSchema;
    GraphSchema schema;
    Long resultNum = 0L;
    if (object instanceof GraphTraversal.Admin || object instanceof DfsTraversal) {
        QueryStatus queryStatus;
        GraphTraversal.Admin traversal = (object instanceof GraphTraversal.Admin) ? GraphTraversal.Admin.class.cast(object) : (DfsTraversal.class.cast(object)).getTraversal();
        String queryString = traversal.toString();
        logger.info("Receive traversal query=>" + queryString);
        if (!traversal.isLocked()) {
            traversal.getStrategies().removeStrategies(ProfileStrategy.class, MxGraphStepStrategy.class, FilterRankingStrategy.class);
        }
        traversal.applyStrategies();
        NettyVertexRpcProcessor nettyVertexRpcProcessor;
        QueryFlowManager queryFlowManager;
        // 保证一查看到snapshotId就开始维护query_status
        synchronized (queryCallbackManager) {
            snapshotSchema = schemaFetcher.getSchemaSnapshotPair();
            queryStatus = queryCallbackManager.beforeExecution(snapshotSchema.getRight());
        }
        schema = snapshotSchema.getLeft();
        LogicalPlanOptimizer planOptimizer = new LogicalPlanOptimizer(new OptimizeConfig(), this.globalPullGraphFlag, schema, snapshotSchema.getRight(), this.lambdaEnableFlag);
        final int resultIterationBatchSize = (Integer) context.getRequestMessage().optionalArgs(Tokens.ARGS_BATCH_SIZE).orElse(this.resultIterationBatchSize);
        nettyVertexRpcProcessor = new NettyTraverserVertexProcessor(context, resultIterationBatchSize, false);
        try {
            queryFlowManager = (object instanceof GraphTraversal.Admin) ? planOptimizer.build(GraphTraversal.class.cast(traversal)) : planOptimizer.build(DfsTraversal.class.cast(object));
        } catch (IllegalArgumentException iae) {
            if (iae.getMessage().contains("MaxGraphIoStep")) {
                logger.info("do maxgraph io step");
                while (traversal.hasNext()) {
                    logger.info("maxgraph io hasNext");
                }
                nettyVertexRpcProcessor.finish(ResponseStatusCode.SUCCESS);
                return 0L;
            }
            throw iae;
        }
        try {
            boolean isLambdaExisted = TraversalHelper.anyStepRecursively(s -> s instanceof LambdaHolder, (Traversal.Admin<?, ?>) traversal);
            queryFlowManager.getQueryFlow().setFrontId(serverId);
            if (this.lambdaEnableFlag && isLambdaExisted) {
                final ObjectMapper mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).addCustomModule(GraphSONXModuleV3d0.build().create(false)).create().createMapper();
                Bytecode bytecode = (Bytecode) context.getRequestMessage().getArgs().get(Tokens.ARGS_GREMLIN);
                byte[] bytecodeByte = mapper.writeValueAsBytes(bytecode);
                queryFlowManager.getQueryFlow().setLambdaExisted(isLambdaExisted).setBytecode(ByteString.copyFrom(bytecodeByte));
            }
            GremlinResultTransform gremlinResultTransform = new GremlinResultTransform(remoteRpcConnector, nettyVertexRpcProcessor, this.graph, queryFlowManager.getResultValueType(), vertexCacheFlag);
            NettyResultProcessor nettyResultProcessor = new NettyResultProcessor(queryId, traversal.toString(), context, new ExecuteConfig().getBatchQuerySize(), resultIterationBatchSize, false);
            nettyResultProcessor.setSchema(schema);
            nettyResultProcessor.setResultTransform(gremlinResultTransform);
            nettyResultProcessor.setLabelIndexNameList(queryFlowManager.getTreeNodeLabelManager().getUserIndexLabelList());
            TimelyQuery timelyQuery = new TimelyQuery(queryFlowManager, nettyResultProcessor, this.graph);
            Logging.query(this.graphName, FRONTEND, this.serverId, queryId, QueryType.EXECUTE, QueryEvent.PLAN_GENERATED, timer.elapsed(TimeUnit.NANOSECONDS), null, null, "");
            timelyExecutor.execute(timelyQuery, schema, timeout, queryId);
            resultNum = nettyResultProcessor.total();
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        } finally {
            queryCallbackManager.afterExecution(queryStatus);
        }
    } else {
        throw new IllegalArgumentException("Not support to process=>" + object);
    }
    return resultNum;
}
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) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) DfsTraversal(com.alibaba.maxgraph.compiler.dfs.DfsTraversal) QueryFlowManager(com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager) ByteString(com.google.protobuf.ByteString) QueryStatus(com.alibaba.maxgraph.api.query.QueryStatus) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Bytecode(org.apache.tinkerpop.gremlin.process.traversal.Bytecode) JsonProcessingException(org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) OptimizeConfig(com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig) LogicalPlanOptimizer(com.alibaba.maxgraph.compiler.optimizer.LogicalPlanOptimizer) ExecuteConfig(com.alibaba.maxgraph.compiler.executor.ExecuteConfig)

Example 3 with QueryStatus

use of com.alibaba.maxgraph.api.query.QueryStatus 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

QueryStatus (com.alibaba.maxgraph.api.query.QueryStatus)3 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)2 DfsTraversal (com.alibaba.maxgraph.compiler.dfs.DfsTraversal)2 LogicalPlanOptimizer (com.alibaba.maxgraph.compiler.optimizer.LogicalPlanOptimizer)2 OptimizeConfig (com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig)2 QueryFlowManager (com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager)2 TimelyQuery (com.alibaba.maxgraph.compiler.query.TimelyQuery)2 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 LambdaHolder (org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder)2 QueryCallbackManager (com.alibaba.maxgraph.api.query.QueryCallbackManager)1 RetryGremlinException (com.alibaba.maxgraph.compiler.exception.RetryGremlinException)1 ExecuteConfig (com.alibaba.maxgraph.compiler.executor.ExecuteConfig)1 PreparedTraversal (com.alibaba.maxgraph.compiler.prepare.PreparedTraversal)1 MixedOpProcessor (com.alibaba.maxgraph.server.processor.MixedOpProcessor)1 MixedTraversalOpProcessor (com.alibaba.maxgraph.server.processor.MixedTraversalOpProcessor)1 ByteString (com.google.protobuf.ByteString)1 Bytecode (org.apache.tinkerpop.gremlin.process.traversal.Bytecode)1 JsonProcessingException (org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException)1 ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)1