YongGang commented on code in PR #14643:
URL: https://github.com/apache/druid/pull/14643#discussion_r1275223485
##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/KubernetesTaskRunner.java:
##########
@@ -134,46 +134,37 @@ public Optional<InputStream> streamTaskLog(String taskid,
long offset)
@Override
public ListenableFuture<TaskStatus> run(Task task)
{
- return tasks.computeIfAbsent(
- task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() ->
runTask(task)))
- ).getResult();
+ return runOrJoinTask(task, true);
}
- protected ListenableFuture<TaskStatus> joinAsync(Task task)
+ protected ListenableFuture<TaskStatus> runOrJoinTask(Task task, boolean run)
{
- return tasks.computeIfAbsent(
- task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() ->
joinTask(task)))
- ).getResult();
- }
-
- private TaskStatus runTask(Task task)
- {
- return doTask(task, true);
- }
-
- private TaskStatus joinTask(Task task)
- {
- return doTask(task, false);
+ synchronized (tasks) {
+ tasks.computeIfAbsent(task.getId(), k -> new KubernetesWorkItem(task,
exec.submit(() -> doTask(task, run))));
+ return tasks.get(task.getId()).getResult();
+ }
}
@VisibleForTesting
protected TaskStatus doTask(Task task, boolean run)
{
- KubernetesPeonLifecycle peonLifecycle = peonLifecycleFactory.build(task);
+ try {
+ KubernetesPeonLifecycle peonLifecycle = peonLifecycleFactory.build(task);
- KubernetesWorkItem workItem = tasks.get(task.getId());
+ synchronized (tasks) {
+ KubernetesWorkItem workItem = tasks.get(task.getId());
- if (workItem == null) {
- throw new ISE("Task [%s] disappeared", task.getId());
- }
+ if (workItem == null) {
+ throw new ISE("Task [%s] disappeared", task.getId());
Review Comment:
I looked at what other TaskRunners do so we can have consistent behavior
(throw error or return task failure).
In
[ThreadingTaskRunner](https://github.com/apache/druid/blob/master/indexing-service/src/main/java/org/apache/druid/indexing/overlord/ThreadingTaskRunner.java#L192-L200),
seems the code is similar to what we have here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]