dybyte commented on code in PR #11924:
URL: https://github.com/apache/seatunnel/pull/11924#discussion_r3845819148
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/TaskExecutionService.java:
##########
@@ -720,17 +748,44 @@ public void cancelTaskGroup(TaskGroupLocation
taskGroupLocation) {
* @param task the Runnable to execute
*/
public void asyncExecuteFunction(TaskGroupLocation taskGroupLocation,
Runnable task) {
+ asyncExecuteFunction(taskGroupLocation, task, null);
+ }
+
+ public void asyncExecuteFunction(
+ TaskGroupLocation taskGroupLocation,
+ Runnable task,
+ ExecutionGeneration executionGeneration) {
String id = UUID.randomUUID().toString();
logger.fine("accept async execute function from " + taskGroupLocation
+ " with id " + id);
- if (!taskAsyncFunctionFuture.containsKey(taskGroupLocation)) {
- taskAsyncFunctionFuture.put(taskGroupLocation, new
ConcurrentHashMap<>());
- }
+ Map<String, CompletableFuture<?>> groupFutures =
+ taskAsyncFunctionFuture.computeIfAbsent(
+ taskGroupLocation, ignored -> new
ConcurrentHashMap<>());
CompletableFuture<?> future =
CompletableFuture.runAsync(task,
MDCTracer.tracing(executorService));
- taskAsyncFunctionFuture.get(taskGroupLocation).put(id, future);
+ groupFutures.put(id, future);
+ if (executionGeneration != null) {
+ taskAsyncFunctionFutureByGeneration
+ .computeIfAbsent(executionGeneration, ignored -> new
ConcurrentHashMap<>())
+ .put(id, future);
+ }
future.whenComplete(
(r, e) -> {
- taskAsyncFunctionFuture.get(taskGroupLocation).remove(id);
+ Map<String, CompletableFuture<?>> futures =
+ taskAsyncFunctionFuture.get(taskGroupLocation);
+ if (futures != null) {
+ futures.remove(id, future);
+ }
+ if (executionGeneration != null) {
+ Map<String, CompletableFuture<?>> generationFutures =
+
taskAsyncFunctionFutureByGeneration.get(executionGeneration);
+ if (generationFutures != null) {
+ generationFutures.remove(id, future);
+ if (generationFutures.isEmpty()) {
+ taskAsyncFunctionFutureByGeneration.remove(
+ executionGeneration,
generationFutures);
+ }
+ }
Review Comment:
Could there be a race here between `generationFutures.isEmpty()` and
removing the generation entry? If another async function is added to the same
generation in between, it may be added to the same map just before the outer
entry is removed, so a later `cancelAsyncFunction()` would no longer be able to
find that future.
--
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]