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);
}
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);
}
}
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;
}
}
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);
}
}
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);
}
}
}
Aggregations