Search in sources :

Example 1 with RpcAddress

use of com.alibaba.maxgraph.common.rpc.RpcAddress in project GraphScope by alibaba.

the class ExecutorAddressFetcher method getAddressList.

@Override
public List<RpcAddress> getAddressList() {
    List<RpcAddress> rpcAddressList = Lists.newArrayList();
    for (int i = 1; i <= clientManager.getExecutorCount(); i++) {
        Endpoint endpoint = clientManager.getExecutor(i);
        rpcAddressList.add(new RpcAddress(endpoint.getIp(), endpoint.getPort()));
    }
    return rpcAddressList;
}
Also used : RpcAddress(com.alibaba.maxgraph.common.rpc.RpcAddress) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint)

Example 2 with RpcAddress

use of com.alibaba.maxgraph.common.rpc.RpcAddress in project GraphScope by alibaba.

the class RemoteRpcConnector method queryVertices.

public void queryVertices(Map<Integer, Map<ElementId, Integer>> classified, GraphSchema schema, TinkerMaxGraph graph, Context context, int batchSize, List<Object> resultList, boolean vertexCacheFlag, RpcProcessorType rpcProcessorType, Map<CompositeId, Map<String, Object>> existPropMap) {
    List<RpcAddress> remoteAddressList = addressFetcher.getAddressList();
    if (classified.size() > remoteAddressList.size()) {
        throw new IllegalArgumentException("classified=>" + classified.keySet() + " count > remote address list=>" + remoteAddressList.toString());
    }
    int classifiedCount = classified.size();
    CountDownLatch latch = new CountDownLatch(classifiedCount);
    ExceptionHolder exceptionHolder = new ExceptionHolder();
    List<RemoteRpcProcessor> remoteRpcProcessorList = Lists.newArrayListWithCapacity(classifiedCount);
    for (Map.Entry<Integer, Map<ElementId, Integer>> entry : classified.entrySet()) {
        if (entry.getKey() < 0) {
            throw new RuntimeException("Invalid key in " + classified + " when get detail of vertex");
        }
        RpcAddress rpcAddress = remoteAddressList.get(entry.getKey());
        LOG.info("Get rpc address " + rpcAddress + " for store id " + entry.getKey());
        try {
            ManagedChannel managedChannel = channels.get(rpcAddress);
            GremlinServiceGrpc.GremlinServiceStub gremlinServiceStub = GremlinServiceGrpc.newStub(managedChannel);
            GremlinQuery.VertexRequest.Builder reqBuilder = GremlinQuery.VertexRequest.newBuilder();
            Map<ElementId, Integer> vertexCountList = entry.getValue();
            for (ElementId elementId : vertexCountList.keySet()) {
                reqBuilder.addIds(GremlinQuery.VertexId.newBuilder().setId(elementId.id()).setTypeId(elementId.typeId()).build());
            }
            RemoteRpcProcessor remoteRpcProcessor = createRemoteRpcProcessor(rpcProcessorType, context, batchSize);
            remoteRpcProcessorList.add(remoteRpcProcessor);
            VertexStreamObserver vertexStreamObserver = new VertexStreamObserver(remoteRpcProcessor, schema, graph, exceptionHolder, latch, vertexCountList, vertexCacheFlag, existPropMap);
            gremlinServiceStub.getVertexs(reqBuilder.build(), vertexStreamObserver);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
    try {
        if (!latch.await(rpcConfig.getQueryTimeoutSec(), TimeUnit.SECONDS)) {
            throw new RuntimeException("Wait query vertex complete time out");
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    if (exceptionHolder.getException() != null) {
        LOG.error("query vertex from store service fail", exceptionHolder.getException());
        throw new RuntimeException(exceptionHolder.getException());
    }
    if (null != resultList) {
        for (RemoteRpcProcessor remoteRpcProcessor : remoteRpcProcessorList) {
            resultList.addAll(remoteRpcProcessor.getResultList());
        }
    }
}
Also used : ExceptionHolder(com.alibaba.maxgraph.sdk.exception.ExceptionHolder) CountDownLatch(java.util.concurrent.CountDownLatch) RpcAddress(com.alibaba.maxgraph.common.rpc.RpcAddress) ManagedChannel(io.grpc.ManagedChannel) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId) GremlinServiceGrpc(com.alibaba.maxgraph.proto.GremlinServiceGrpc)

Aggregations

RpcAddress (com.alibaba.maxgraph.common.rpc.RpcAddress)2 GremlinServiceGrpc (com.alibaba.maxgraph.proto.GremlinServiceGrpc)1 ExceptionHolder (com.alibaba.maxgraph.sdk.exception.ExceptionHolder)1 Endpoint (com.alibaba.maxgraph.sdkcommon.client.Endpoint)1 ElementId (com.alibaba.maxgraph.sdkcommon.graph.ElementId)1 ManagedChannel (io.grpc.ManagedChannel)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1