Search in sources :

Example 1 with LockWrapper

use of com.alibaba.maxgraph.common.lock.LockWrapper in project GraphScope by alibaba.

the class PartitionManager method getServerAssignment.

public ServerAssignment getServerAssignment(Integer serverId) throws Exception {
    ServerAssignment serverAssignment = assignments.get(serverId);
    if (serverAssignment == null) {
        try (LockWrapper ignore = partitionLock.openWriteLock()) {
            serverAssignment = assignments.get(serverId);
            if (serverAssignment == null) {
                LOG.info("assigner:{}, instance config:{}", assigner, instanceConfig);
                List<Integer> assignment = assigner.getAssignment(instanceConfig.getPartitionNum(), instanceConfig.getResourceExecutorCount(), serverId, replicaCount);
                serverAssignment = new ServerAssignment(serverId, assignment);
                LOG.info("assign partition to server {}: {}", serverId, assignment);
                Map<Integer, ServerAssignment> temp = Maps.newHashMap(assignments);
                temp.put(serverId, serverAssignment);
                serverDataManager.namingProxy.persistentServerAssignment(temp);
                assignments.put(serverId, serverAssignment);
            }
            return serverAssignment;
        }
    }
    return assignments.get(serverId);
}
Also used : LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper) ServerAssignment(com.alibaba.maxgraph.common.ServerAssignment)

Example 2 with LockWrapper

use of com.alibaba.maxgraph.common.lock.LockWrapper 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 LockWrapper

use of com.alibaba.maxgraph.common.lock.LockWrapper in project GraphScope by alibaba.

the class InstanceInfo method isAllWorkerRunning.

public boolean isAllWorkerRunning() {
    try (LockWrapper ignore = lock.openReadLock()) {
        long resourceExecutorCount = instanceConfig.getResourceExecutorCount();
        long resourceIngestNodeCount = instanceConfig.getResourceIngestNodeCount();
        long resourceFrontendCount = instanceConfig.getResourceFrontendCount();
        long eSize = workerInfoMap.get(RoleType.EXECUTOR).stream().filter(r -> r.workerStatus == WorkerStatus.RUNNING).count();
        long iSize = workerInfoMap.get(RoleType.INGEST_NODE).stream().filter(r -> r.workerStatus == WorkerStatus.RUNNING).count();
        long fSize = workerInfoMap.get(RoleType.FRONTEND).stream().filter(r -> r.workerStatus == WorkerStatus.RUNNING).count();
        if (resourceExecutorCount == eSize && resourceIngestNodeCount == iSize && resourceFrontendCount == fSize) {
            return true;
        }
        return false;
    }
}
Also used : CommonUtil(com.alibaba.maxgraph.common.util.CommonUtil) java.util(java.util) com.alibaba.maxgraph.proto(com.alibaba.maxgraph.proto) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ConcurrentMap(java.util.concurrent.ConcurrentMap) ServerAssignment(com.alibaba.maxgraph.common.ServerAssignment) Pair(org.apache.commons.lang3.tuple.Pair) DataStatus(com.alibaba.maxgraph.common.DataStatus) WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) ExtendedRWLock(com.alibaba.maxgraph.common.lock.ExtendedRWLock) com.google.common.collect(com.google.common.collect) LogEvents(com.alibaba.maxgraph.logging.LogEvents) Logger(org.slf4j.Logger) ABNORMAL(com.alibaba.maxgraph.proto.InstanceInfoProto.Status.ABNORMAL) InstanceConfig(com.alibaba.maxgraph.common.cluster.InstanceConfig) Logging(com.alibaba.maxgraph.logging.Logging) Collectors(java.util.stream.Collectors) NORMAL(com.alibaba.maxgraph.proto.InstanceInfoProto.Status.NORMAL) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper) Protoable(com.alibaba.maxgraph.sdkcommon.Protoable) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) Joiner(com.google.common.base.Joiner) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper)

Example 4 with LockWrapper

use of com.alibaba.maxgraph.common.lock.LockWrapper 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 5 with LockWrapper

use of com.alibaba.maxgraph.common.lock.LockWrapper 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

LockWrapper (com.alibaba.maxgraph.common.lock.LockWrapper)7 WorkerInfo (com.alibaba.maxgraph.common.client.WorkerInfo)6 ServerAssignment (com.alibaba.maxgraph.common.ServerAssignment)3 Endpoint (com.alibaba.maxgraph.sdkcommon.client.Endpoint)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 DataStatus (com.alibaba.maxgraph.common.DataStatus)1 InstanceConfig (com.alibaba.maxgraph.common.cluster.InstanceConfig)1 ExtendedRWLock (com.alibaba.maxgraph.common.lock.ExtendedRWLock)1 CommonUtil (com.alibaba.maxgraph.common.util.CommonUtil)1 LogEvents (com.alibaba.maxgraph.logging.LogEvents)1 Logging (com.alibaba.maxgraph.logging.Logging)1 com.alibaba.maxgraph.proto (com.alibaba.maxgraph.proto)1 ABNORMAL (com.alibaba.maxgraph.proto.InstanceInfoProto.Status.ABNORMAL)1 NORMAL (com.alibaba.maxgraph.proto.InstanceInfoProto.Status.NORMAL)1 Protoable (com.alibaba.maxgraph.sdkcommon.Protoable)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 com.google.common.collect (com.google.common.collect)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1