use of com.alibaba.maxgraph.sdkcommon.client.Endpoint in project GraphScope by alibaba.
the class CoordinatorRpcServer method resendRequest.
void resendRequest(HeartbeartRequest request) {
NodeInfo nodeInfo = request.getNodeInfo();
RoleType role = nodeInfo.getNodeId().getRole();
int serverID = nodeInfo.getServerId();
serverDataManager.instanceInfo.onSimpleHeartBeat(role, serverID, new Endpoint(nodeInfo.getHost(), nodeInfo.getPort()), request.getLogDir());
}
use of com.alibaba.maxgraph.sdkcommon.client.Endpoint in project GraphScope by alibaba.
the class WorkerManagerApiServerTest method testReadRuntimeEnvsFromBinary.
@Test
public void testReadRuntimeEnvsFromBinary() throws InvalidProtocolBufferException {
String logDir = "";
InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setWorkerInfo(RoleType.EXECUTOR, 0, new Endpoint("127.0.0.1", 1, 2), logDir);
instanceInfo.setWorkerInfo(RoleType.EXECUTOR, 1, new Endpoint("127.0.0.1", 1, 2), logDir);
instanceInfo.setWorkerInfo(RoleType.EXECUTOR, 2, new Endpoint("127.0.0.1", 1, 2), logDir);
instanceInfo.setWorkerInfo(RoleType.EXECUTOR, 3, new Endpoint("127.0.0.1", 1, 2), logDir);
instanceInfo.updateExecutorRuntimeEnv(0, "127.0.0.1", 3);
instanceInfo.updateExecutorRuntimeEnv(1, "127.0.0.1", 4);
instanceInfo.updateExecutorRuntimeEnv(2, "127.0.0.1", 5);
List<String> envs = instanceInfo.updateExecutorRuntimeEnv(3, "127.0.0.1", 6);
RuntimeEnvList.Builder builder = RuntimeEnvList.newBuilder();
envs.forEach(builder::addEnvs);
byte[] binary = builder.build().toByteArray();
RuntimeEnvList envList = RuntimeEnvList.parseFrom(binary);
List<String> envs2 = Lists.newArrayList(envList.getEnvsList().iterator());
Assert.assertEquals(envs2, Lists.newArrayList("127.0.0.1:3", "127.0.0.1:4", "127.0.0.1:5", "127.0.0.1:6"));
}
use of com.alibaba.maxgraph.sdkcommon.client.Endpoint in project GraphScope by alibaba.
the class RpcConnector method query.
public void query(QueryFlowOuterClass.QueryFlow.Builder queryFlow, TimelyResultProcessor resultProcessor, GraphSchema schema, Graph graph, long timeout, boolean isAsync) throws Exception {
ExceptionHolder exceptionHolder = new ExceptionHolder();
List<Endpoint> executorAddrList = getTargetExecutorAddrs();
int executorCount = executorAddrList.size();
CountDownLatch latch = new CountDownLatch(executorCount);
Stopwatch stopwatch = Stopwatch.createStarted();
LOG.info("Query plan=>" + TextFormat.printToString(queryFlow));
List<StreamObserver> streamObserverList = new ArrayList<>();
for (int i = 0; i < executorAddrList.size(); i++) {
streamObserverList.add(new QueryStreamObserver(resultProcessor, schema, graph, exceptionHolder, latch, queryFlow.getQueryId()));
}
long currentTimeOut = queryFlow.getTimeoutMs();
if (currentTimeOut == 0) {
queryFlow.setTimeoutMs(timeout);
currentTimeOut = timeout;
}
queryFlow.setStartTimestampMs(System.currentTimeMillis());
QueryFlowOuterClass.QueryFlow queryFlowPlan = queryFlow.build();
if (isAsync) {
for (int i = 0; i < executorAddrList.size(); i++) {
IpPort address = IpPort.fromCtrlAndAsyncEndpoint(executorAddrList.get(i));
ManagedChannel randomChannel = channels.get(address).get(RandomUtils.nextInt(0, channelCount)).getRight();
ConnectivityState connectivityState = randomChannel.getState(true);
if (connectivityState != ConnectivityState.IDLE && connectivityState != ConnectivityState.READY) {
LOG.warn("refresh connection for " + address + " with connectivity state " + connectivityState);
channels.refresh(address);
randomChannel = channels.get(address).get(RandomUtils.nextInt(0, channelCount)).getRight();
}
connectivityState = randomChannel.getState(true);
LOG.info("Connectivity state from " + address + " " + connectivityState);
AsyncMaxGraphServiceGrpc.newStub(randomChannel).asyncExecute(queryFlowPlan, streamObserverList.get(i));
}
} else {
for (int i = 0; i < executorAddrList.size(); i++) {
IpPort address = IpPort.fromGremlinEndpoint(executorAddrList.get(i));
MaxGraphServiceStub gremlinServiceStub = channels.get(address).get(RandomUtils.nextInt(0, channelCount)).getLeft();
gremlinServiceStub.execute(queryFlowPlan, streamObserverList.get(i));
}
}
long sendTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
long awaitStart = System.currentTimeMillis();
long waitTimeOut = currentTimeOut;
while (true) {
try {
if (!latch.await(waitTimeOut, TimeUnit.MILLISECONDS)) {
// try to check if executor is exit
getTargetExecutorAddrs();
if (exceptionHolder.getException() != null) {
LOG.error("query from timely fail", exceptionHolder.getException());
throw new RuntimeException(exceptionHolder.getException());
}
throw new RuntimeException("Wait query complete time out for " + (currentTimeOut / 1000.0) + " secs");
}
break;
} catch (InterruptedException e) {
if (exceptionHolder.getException() != null) {
LOG.error("query from timely fail", exceptionHolder.getException());
throw new RuntimeException(exceptionHolder.getException());
}
long currentTime = System.currentTimeMillis();
waitTimeOut = currentTimeOut - (currentTime - awaitStart);
if (waitTimeOut <= 0) {
break;
}
LOG.error("thread interrupted, continue to wait " + waitTimeOut + "ms");
}
}
if (exceptionHolder.getException() != null) {
LOG.error("query from timely fail", exceptionHolder.getException());
throw new RuntimeException(exceptionHolder.getException());
}
processEmptyResult(resultProcessor, queryFlowPlan);
long queryTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
resultProcessor.finish();
long finishTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
LOG.info("finish query " + queryFlow.getQueryId() + " send cost=>" + sendTime + ", query cost=>" + (queryTime - sendTime) + "ms, finish cost=>" + (finishTime - queryTime) + "ms, total cost=>" + finishTime + "ms, query count=> " + resultProcessor.total());
stopwatch.stop();
}
use of com.alibaba.maxgraph.sdkcommon.client.Endpoint in project GraphScope by alibaba.
the class RpcConnector method cancelDataflowByFront.
public void cancelDataflowByFront(int frontId, List<Endpoint> serverList) throws Exception {
for (Endpoint entry : serverList) {
IpPort address = IpPort.fromCtrlAndAsyncEndpoint(entry);
ManagedChannel randomChannel = channels.get(address).get(RandomUtils.nextInt(0, channelCount)).getRight();
MaxGraphCtrlServiceBlockingStub stub = MaxGraphCtrlServiceGrpc.newBlockingStub(randomChannel);
CancelDataflowResponse resp = stub.cancelDataflowByFront(GremlinService.CancelDataflowByFrontRequest.newBuilder().setFrontId(frontId).build());
if (!resp.getSuccess()) {
throw new RuntimeException("request cancelDataflowByFront to server " + address + " by frontend " + frontId + " fail: " + resp.getMessage());
}
}
}
use of com.alibaba.maxgraph.sdkcommon.client.Endpoint in project GraphScope by alibaba.
the class ClientManager method updateExecutorMap.
public void updateExecutorMap(int workerId, Endpoint endpoint) {
Endpoint existEndpoint = executorEndpointMap.get(workerId);
if (!endpoint.equals(existEndpoint)) {
executorEndpointMap.put(workerId, endpoint);
executorUpdateVersion.set(System.currentTimeMillis());
}
}
Aggregations