morningman commented on a change in pull request #333: Add distributor which
schedule task to be fairly
URL: https://github.com/apache/incubator-doris/pull/333#discussion_r235583194
##########
File path:
fe/src/main/java/org/apache/doris/load/routineload/RoutineLoadManager.java
##########
@@ -107,37 +160,93 @@ public void addRoutineLoadTasks(List<RoutineLoadTask>
routineLoadTaskList) {
}
}
- public Map<Long, RoutineLoadTask> getIdToRoutineLoadTask() {
- return idToRoutineLoadTask;
+ public Map<Long, RoutineLoadTaskInfo> getIdToRoutineLoadTask() {
+ readLock();
+ try {
+ return idToRoutineLoadTask;
+ } finally {
+ readUnlock();
+ }
}
- public void addNeedSchedulerRoutineLoadTasks(List<RoutineLoadTask>
routineLoadTaskList) {
+ public void addNeedSchedulerRoutineLoadTasks(List<RoutineLoadTaskInfo>
routineLoadTaskList, long routineLoadJobId) {
writeLock();
try {
-
idToNeedSchedulerRoutineLoadTask.putAll(routineLoadTaskList.parallelStream().collect(
- Collectors.toMap(task -> task.getSignature(), task ->
task)));
+ routineLoadTaskList.parallelStream().forEach(entity ->
needSchedulerRoutineLoadTasks.add(entity));
+ routineLoadTaskList.parallelStream().forEach(entity ->
+ taskIdToJobId.put(entity.getSignature(),
routineLoadJobId));
} finally {
writeUnlock();
}
}
- public void removeRoutineLoadTasks(List<RoutineLoadTask> routineLoadTasks)
{
+ public void removeRoutineLoadTasks(List<RoutineLoadTaskInfo>
routineLoadTasks) {
if (routineLoadTasks != null) {
writeLock();
try {
routineLoadTasks.parallelStream().forEach(task ->
idToRoutineLoadTask.remove(task.getSignature()));
routineLoadTasks.parallelStream().forEach(task ->
-
idToNeedSchedulerRoutineLoadTask.remove(task.getSignature()));
+ needSchedulerRoutineLoadTasks.remove(task));
+ routineLoadTasks.parallelStream().forEach(task ->
taskIdToJobId.remove(task.getSignature()));
} finally {
writeUnlock();
}
}
}
- public Map<Long, RoutineLoadTask> getIdToNeedSchedulerRoutineLoadTasks() {
+ public int getClusterIdleSlotNum() {
+ readLock();
+ try {
+ int result = 0;
+ initBeIdToMaxConcurrentTasks();
+ for (Map.Entry<Long, Integer> entry :
beIdToMaxConcurrentTasks.entrySet()) {
+ if (beIdToConcurrentTasks.get(entry.getKey()) == null) {
+ result += entry.getValue();
+ } else {
+ result += entry.getValue() -
beIdToConcurrentTasks.get(entry.getKey());
+ }
+ }
+ return result;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public long getMinTaskBeId() {
+ readLock();
+ try {
+ long result = 0L;
+ int maxIdleSlotNum = 0;
+ initBeIdToMaxConcurrentTasks();
+ for (Map.Entry<Long, Integer> entry :
beIdToMaxConcurrentTasks.entrySet()) {
+ if (beIdToConcurrentTasks.get(entry.getKey()) == null) {
+ result = maxIdleSlotNum < entry.getValue() ?
entry.getKey() : result;
+ maxIdleSlotNum = Math.max(maxIdleSlotNum,
entry.getValue());
+ } else {
+ int idelTaskNum = entry.getValue() -
beIdToConcurrentTasks.get(entry.getKey());
+ result = maxIdleSlotNum < idelTaskNum ? entry.getKey() :
result;
+ maxIdleSlotNum = Math.max(maxIdleSlotNum, idelTaskNum);
+ }
+ }
+ return result;
+ } finally {
+ readUnlock();
+ }
+ }
+
+ public Queue<RoutineLoadTaskInfo> getNeedSchedulerRoutineLoadTasks() {
+ readLock();
Review comment:
Still, this lock protects nothing.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]