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;
}
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());
}
}
}
Aggregations