Search in sources :

Example 6 with Endpoint

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());
}
Also used : Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint)

Example 7 with Endpoint

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"));
}
Also used : RuntimeEnvList(com.alibaba.maxgraph.proto.RuntimeEnvList) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) InstanceInfo(com.alibaba.maxgraph.coordinator.manager.InstanceInfo) Test(org.junit.Test)

Example 8 with Endpoint

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();
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ExceptionHolder(com.alibaba.maxgraph.sdk.exception.ExceptionHolder) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) ConnectivityState(io.grpc.ConnectivityState) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) MaxGraphServiceStub(com.alibaba.maxgraph.rpc.MaxGraphServiceGrpc.MaxGraphServiceStub) ManagedChannel(io.grpc.ManagedChannel)

Example 9 with Endpoint

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());
        }
    }
}
Also used : Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) MaxGraphCtrlServiceBlockingStub(com.alibaba.maxgraph.rpc.MaxGraphCtrlServiceGrpc.MaxGraphCtrlServiceBlockingStub) ManagedChannel(io.grpc.ManagedChannel)

Example 10 with Endpoint

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());
    }
}
Also used : Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint)

Aggregations

Endpoint (com.alibaba.maxgraph.sdkcommon.client.Endpoint)21 WorkerInfo (com.alibaba.maxgraph.common.client.WorkerInfo)3 MaxGraphCtrlServiceBlockingStub (com.alibaba.maxgraph.rpc.MaxGraphCtrlServiceGrpc.MaxGraphCtrlServiceBlockingStub)3 ManagedChannel (io.grpc.ManagedChannel)3 InstanceInfo (com.alibaba.maxgraph.coordinator.manager.InstanceInfo)2 ArrayList (java.util.ArrayList)2 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)1 InstanceStatus (com.alibaba.maxgraph.common.InstanceStatus)1 ServerAssignment (com.alibaba.maxgraph.common.ServerAssignment)1 InstanceConfig (com.alibaba.maxgraph.common.cluster.InstanceConfig)1 LockWrapper (com.alibaba.maxgraph.common.lock.LockWrapper)1 RpcAddress (com.alibaba.maxgraph.common.rpc.RpcAddress)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 SchemaFetcher (com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher)1 ServerDataApiClient (com.alibaba.maxgraph.coordinator.client.ServerDataApiClient)1 IteratorList (com.alibaba.maxgraph.iterator.IteratorList)1 RoleType (com.alibaba.maxgraph.proto.RoleType)1 RoutingServerInfoResp (com.alibaba.maxgraph.proto.RoutingServerInfoResp)1 RuntimeEnvList (com.alibaba.maxgraph.proto.RuntimeEnvList)1 PropertyValueResult (com.alibaba.maxgraph.result.PropertyValueResult)1