Search in sources :

Example 1 with WorkerInfo

use of com.alibaba.maxgraph.common.client.WorkerInfo in project GraphScope by alibaba.

the class RemoteGraph method refresh.

@Override
public void refresh() throws Exception {
    InstanceStatus serverStatuses = clientManager.getServerDataApiClient().getServerStatuses();
    List<RemoteProxy> proxys = new ArrayList<>(serverStatuses.server2WorkerInfo.size());
    Set<WorkerInfo> workerInfoSet = new TreeSet<>(serverStatuses.getWorkInfo(RoleType.EXECUTOR));
    for (WorkerInfo v : workerInfoSet) {
        if (serverStatuses.assignments.containsKey(v.id)) {
            ServerAssignment serverAssignment = serverStatuses.readServerAssignment(v.id);
            serverAssignment.getPartitions().forEach(p -> partitionDistri.put(p, v.id));
            proxys.add(new RemoteProxy(v.endpoint.getIp(), v.endpoint.getPort(), 120L, schemaFetcher, this));
        }
    }
    List<Endpoint> endpointList = workerInfoSet.stream().map(workerInfo -> workerInfo.endpoint).collect(toList());
    LOG.info("proxys: {}", JSON.toJson(endpointList));
    List<RemoteProxy> prevProxyList = this.proxys;
    this.proxys = proxys;
    try {
        for (RemoteProxy remoteProxy : prevProxyList) {
            remoteProxy.close();
        }
    } finally {
        LOG.info("Close all previous remote proxy");
    }
    // TODO : dynamic configuration of different Graph Partitioner;
    this.partitioner = new DefaultGraphPartitioner(schemaFetcher.getPartitionNum());
}
Also used : GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) java.util(java.util) ElementId(com.alibaba.maxgraph.sdkcommon.graph.ElementId) CompositeId(com.alibaba.maxgraph.sdkcommon.graph.CompositeId) LoggerFactory(org.slf4j.LoggerFactory) DefaultGraphPartitioner(com.alibaba.maxgraph.structure.DefaultGraphPartitioner) GraphPartitioner(com.alibaba.maxgraph.structure.GraphPartitioner) Edge(com.alibaba.maxgraph.structure.Edge) ServerAssignment(com.alibaba.maxgraph.common.ServerAssignment) Vertex(com.alibaba.maxgraph.structure.Vertex) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) IteratorList(com.alibaba.maxgraph.iterator.IteratorList) WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) IteratorUtils(org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils) JSON(com.alibaba.maxgraph.sdkcommon.util.JSON) Triple(org.apache.commons.lang3.tuple.Triple) IdManager(com.alibaba.maxgraph.structure.IdManager) Logger(org.slf4j.Logger) SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) InstanceStatus(com.alibaba.maxgraph.common.InstanceStatus) InstanceConfig(com.alibaba.maxgraph.common.cluster.InstanceConfig) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) RoleType(com.alibaba.maxgraph.proto.RoleType) MaxGraph(com.alibaba.maxgraph.structure.graph.MaxGraph) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) Direction(org.apache.tinkerpop.gremlin.structure.Direction) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) InstanceStatus(com.alibaba.maxgraph.common.InstanceStatus) WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) DefaultGraphPartitioner(com.alibaba.maxgraph.structure.DefaultGraphPartitioner) ServerAssignment(com.alibaba.maxgraph.common.ServerAssignment)

Example 2 with WorkerInfo

use of com.alibaba.maxgraph.common.client.WorkerInfo in project GraphScope by alibaba.

the class InstanceInfo method setServerStatus.

/**
 * can't modify runtime port when update executor hb
 *
 * @param serverStatus
 */
public void setServerStatus(DataStatus serverStatus) {
    try (LockWrapper ignore = lock.openWriteLock()) {
        WorkerInfo newWorkerInfo = new WorkerInfo(serverStatus);
        int serverId = serverStatus.serverId;
        if (server2WorkerInfo.containsKey(serverId)) {
            WorkerInfo originWorkerInfo = server2WorkerInfo.get(serverId);
            workerInfoMap.remove(RoleType.EXECUTOR, originWorkerInfo);
            newWorkerInfo.endpoint.setRuntimePort(originWorkerInfo.endpoint.getRuntimePort());
            newWorkerInfo.endpoint.updateIp(serverStatus.endpoint.getIp());
            if (originWorkerInfo.workerStatus == WorkerStatus.LOST || originWorkerInfo.workerStatus == WorkerStatus.RESTARTING) {
                logSchedulerEvent(serverId, LogEvents.ScheduleEvent.WORKER_RESUME_RUNNING, "worker " + serverId + " running again at " + CommonUtil.getCurrentDate());
            }
        }
        workerInfoMap.put(RoleType.EXECUTOR, newWorkerInfo);
        server2WorkerInfo.put(serverStatus.serverId, newWorkerInfo);
    }
}
Also used : WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint)

Example 3 with WorkerInfo

use of com.alibaba.maxgraph.common.client.WorkerInfo in project GraphScope by alibaba.

the class InstanceInfo method setWorkerInfo.

public void setWorkerInfo(RoleType roleType, int workerId, Endpoint endpoint, String logDir) {
    WorkerInfo workerInfo = new WorkerInfo(workerId, endpoint, roleType, WorkerStatus.RUNNING, logDir, System.currentTimeMillis());
    try (LockWrapper ignore = lock.openWriteLock()) {
        workerInfoMap.remove(roleType, workerInfo);
        workerInfoMap.put(roleType, workerInfo);
        if (server2WorkerInfo.containsKey(workerId)) {
            WorkerInfo originWorkerInfo = server2WorkerInfo.get(workerId);
            if (originWorkerInfo.workerStatus == WorkerStatus.LOST || originWorkerInfo.workerStatus == WorkerStatus.RESTARTING) {
                logSchedulerEvent(workerId, LogEvents.ScheduleEvent.WORKER_RESUME_RUNNING, "worker " + workerId + " running again at " + CommonUtil.getCurrentDate());
            }
        }
        server2WorkerInfo.put(workerId, workerInfo);
    }
}
Also used : WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper)

Example 4 with WorkerInfo

use of com.alibaba.maxgraph.common.client.WorkerInfo in project GraphScope by alibaba.

the class InstanceInfo method getCurrentRouting.

public List<Integer> getCurrentRouting() {
    List<Integer> routingServerIds = new ArrayList<>();
    Set<WorkerInfo> workerInfoSet = getWorkerInfo(RoleType.EXECUTOR);
    Map<Integer, Set<WorkerInfo>> groupWorkerInfo = new HashMap<>();
    for (WorkerInfo workerInfo : workerInfoSet) {
        int serverId = workerInfo.dataStatus.serverId;
        int groupId = getGroupId(serverId);
        Set<WorkerInfo> workerInfos = groupWorkerInfo.computeIfAbsent(groupId, k -> new HashSet<>());
        workerInfos.add(workerInfo);
    }
    for (int i = 0; i < replicaCount; i++) {
        Set<WorkerInfo> workerInfos = groupWorkerInfo.get(i);
        if (workerInfos == null || workerInfos.size() != executorCount / replicaCount) {
            // bad group
            LOG.error("Invalid group: " + i + ". expected " + executorCount / replicaCount + ", but workers are: " + workerInfos);
            continue;
        }
        boolean badGroup = false;
        for (WorkerInfo workerInfo : workerInfos) {
            if (workerInfo.workerStatus != WorkerStatus.RUNNING) {
                // bad group
                LOG.error("Invalid group: " + i + ". WorkerInfo: " + workerInfo);
                badGroup = true;
                break;
            }
        }
        if (badGroup) {
            continue;
        }
        routingServerIds.add(i * nodesPerGroup + 1);
    }
    return routingServerIds;
}
Also used : WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint)

Example 5 with WorkerInfo

use of com.alibaba.maxgraph.common.client.WorkerInfo in project GraphScope by alibaba.

the class InstanceInfo method updateWorkerStatus.

public void updateWorkerStatus(int workerId, WorkerStatus newStatus) {
    try (LockWrapper ignore = lock.openWriteLock()) {
        if (server2WorkerInfo.containsKey(workerId)) {
            WorkerInfo originWorkerInfo = server2WorkerInfo.get(workerId);
            WorkerInfo newWorkerInfo;
            if (originWorkerInfo.roleType == RoleType.EXECUTOR && originWorkerInfo.dataStatus != null) {
                newWorkerInfo = new WorkerInfo(originWorkerInfo.dataStatus, newStatus);
            } else {
                newWorkerInfo = new WorkerInfo(workerId, originWorkerInfo.endpoint, originWorkerInfo.roleType, newStatus, originWorkerInfo.logDir, originWorkerInfo.lastReportTime);
            }
            workerInfoMap.remove(originWorkerInfo.roleType, originWorkerInfo);
            workerInfoMap.put(originWorkerInfo.roleType, newWorkerInfo);
            server2WorkerInfo.put(workerId, newWorkerInfo);
        }
    }
}
Also used : WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper)

Aggregations

WorkerInfo (com.alibaba.maxgraph.common.client.WorkerInfo)8 LockWrapper (com.alibaba.maxgraph.common.lock.LockWrapper)5 Endpoint (com.alibaba.maxgraph.sdkcommon.client.Endpoint)5 ServerAssignment (com.alibaba.maxgraph.common.ServerAssignment)2 InstanceStatus (com.alibaba.maxgraph.common.InstanceStatus)1 InstanceConfig (com.alibaba.maxgraph.common.cluster.InstanceConfig)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 SchemaFetcher (com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher)1 IteratorList (com.alibaba.maxgraph.iterator.IteratorList)1 RoleType (com.alibaba.maxgraph.proto.RoleType)1 CompositeId (com.alibaba.maxgraph.sdkcommon.graph.CompositeId)1 ElementId (com.alibaba.maxgraph.sdkcommon.graph.ElementId)1 JSON (com.alibaba.maxgraph.sdkcommon.util.JSON)1 DefaultGraphPartitioner (com.alibaba.maxgraph.structure.DefaultGraphPartitioner)1 Edge (com.alibaba.maxgraph.structure.Edge)1 GraphPartitioner (com.alibaba.maxgraph.structure.GraphPartitioner)1 IdManager (com.alibaba.maxgraph.structure.IdManager)1 Vertex (com.alibaba.maxgraph.structure.Vertex)1 MaxGraph (com.alibaba.maxgraph.structure.graph.MaxGraph)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1