zhangshenghang commented on code in PR #11924:
URL: https://github.com/apache/seatunnel/pull/11924#discussion_r3846048150
##########
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:
Good catch. I changed the generation cleanup to use
`taskAsyncFunctionFutureByGeneration.computeIfPresent(...)`, so removing the
finished future and deciding whether to drop the generation entry now happen
atomically for that generation key. This prevents a concurrently registered
future for the same generation from being hidden by a stale outer-map removal.
--
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]