YongGang opened a new pull request, #14643: URL: https://github.com/apache/druid/pull/14643
### Description Seems there is a multi-threading issue introduced from this change to KubernetesTaskRunner https://github.com/apache/druid/pull/14435 Following exception was thrown under high load: ``` org.apache.druid.java.util.common.ISE: Task [partial_dimension_cardinality_xxx] disappeared at org.apache.druid.k8s.overlord.KubernetesTaskRunner.doTask(KubernetesTaskRunner.java:167) ~[?:?] at org.apache.druid.k8s.overlord.KubernetesTaskRunner.runTask(KubernetesTaskRunner.java:151) ~[?:?] at org.apache.druid.k8s.overlord.KubernetesTaskRunner.lambda$null$0(KubernetesTaskRunner.java:138) ~[?:?] at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?] at java.lang.Thread.run(Thread.java:829) ~[?:?] ``` It's due to task is added to `tasks` map from the main thread and in `doTask` (called by `runTask`) it will check task existence from a pool thread thus caused race condition as shown in the following code: ``` return tasks.computeIfAbsent( task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() -> runTask(task))) ).getResult(); ``` Now we use lock to guard the task put and get operation from the same method. #### Release note - fix race condition in K8s task runner. <hr> This PR has: - [x] been self-reviewed. - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.) - [ ] added documentation for new or modified features or behaviors. - [ ] a release note entry in the PR description. - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links. - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md) - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader. - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met. - [ ] added integration tests. - [ ] been tested in a test Druid cluster. -- 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]
