Skip to content

Commit

Permalink
fix running task count bug (opensearch-project#641)
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <[email protected]>

Signed-off-by: Yaliang Wu <[email protected]>
  • Loading branch information
ylwu-amzn committed Feb 17, 2023
1 parent 6f20220 commit 0a146a2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions plugin/src/main/java/org/opensearch/ml/task/MLTaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ public synchronized String checkLimitAndAddRunningTask(MLTask mlTask, Integer li
runningTaskCount.set(0);
}
log.debug("Task id: {}, current running task {}: {}", mlTask.getTaskId(), mlTask.getTaskType(), runningTaskCount.get());
if (runningTaskCount.get() >= limit) {
String error = "exceed max running task limit";
log.info(error + " for task " + mlTask.getTaskId());
return error;
}
if (contains(mlTask.getTaskId())) {
getMLTask(mlTask.getTaskId()).setState(MLTaskState.RUNNING);
} else {
if (runningTaskCount.get() >= limit) {
String error = "exceed max running task limit";
log.info(error + " for task " + mlTask.getTaskId());
return error;
}
mlTask.setState(MLTaskState.RUNNING);
add(mlTask);
runningTaskCount.incrementAndGet();
}
runningTaskCount.incrementAndGet();
return null;
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public void updateMLTask(
) {
MLTaskCache taskCache = taskCaches.get(taskId);
if (removeFromCache) {
taskCaches.remove(taskId);
remove(taskId);
}
if (taskCache == null) {
listener.onFailure(new MLResourceNotFoundException("Can't find task"));
Expand Down Expand Up @@ -409,7 +409,7 @@ public void syncRunningLoadModelTasks(Map<String, Set<String>> runningLoadModelT
if (staleTasks.size() > 0) {
log.debug("remove stale load tasks : {}", Arrays.toString(staleTasks.toArray(new String[0])));
for (String taskId : staleTasks) {
taskCaches.remove(taskId);
remove(taskId);
}
}
}
Expand Down

0 comments on commit 0a146a2

Please sign in to comment.