Search in sources :

Example 6 with LockWrapper

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

the class InstanceInfo method updateExecutorRuntimeEnv.

public List<String> updateExecutorRuntimeEnv(int serverId, String ip, int port) {
    // TODO : Avoid to use a mutex write lock to guard a concurrent hash map ???.
    try (LockWrapper ignore = lock.openWriteLock()) {
        if (server2WorkerInfo.containsKey(serverId)) {
            server2WorkerInfo.get(serverId).endpoint.setRuntimePort(port);
            server2WorkerInfo.get(serverId).endpoint.updateIp(ip);
        } else {
            Endpoint endpoint = new Endpoint(ip, -1);
            endpoint.setRuntimePort(port);
            server2WorkerInfo.put(serverId, new WorkerInfo(serverId, endpoint, RoleType.EXECUTOR, WorkerStatus.RUNNING, StringUtils.EMPTY, System.currentTimeMillis()));
        }
    }
    return getRuntimeEnv();
}
Also used : Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper)

Example 7 with LockWrapper

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

the class InstanceInfo method toSimpleProto.

public InstanceInfoProto.Builder toSimpleProto() {
    InstanceInfoProto.Builder builder = InstanceInfoProto.newBuilder();
    PartitionProtos.Builder pBuilder = PartitionProtos.newBuilder();
    for (Map.Entry<Integer, ServerAssignment> assignmentEntry : serverDataManager.partitionManager.assignments.entrySet()) {
        pBuilder.clear();
        pBuilder.addAllPartitionId(assignmentEntry.getValue().getPartitions());
        builder.putAssignment(assignmentEntry.getKey(), pBuilder.build());
    }
    InstanceInfoProto.Status status = getInstanceServingStatus();
    builder.setStatus(status);
    try (LockWrapper ignore = lock.openReadLock()) {
        WorkerInfoProtos.Builder wBuilder = WorkerInfoProtos.newBuilder();
        for (Map.Entry<RoleType, Collection<WorkerInfo>> workerInfo : workerInfoMap.asMap().entrySet()) {
            wBuilder.clear();
            for (WorkerInfo info : workerInfo.getValue()) {
                wBuilder.addInfos(info.toProto());
            }
            RoleType roleType = workerInfo.getKey();
            builder.putWorkerInfos(roleType.getNumber(), wBuilder.build());
        }
    }
    return builder;
}
Also used : WorkerInfo(com.alibaba.maxgraph.common.client.WorkerInfo) LockWrapper(com.alibaba.maxgraph.common.lock.LockWrapper) ConcurrentMap(java.util.concurrent.ConcurrentMap) ServerAssignment(com.alibaba.maxgraph.common.ServerAssignment)

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