eemario commented on code in PR #27741:
URL: https://github.com/apache/flink/pull/27741#discussion_r2973222058


##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -887,6 +1062,83 @@ private void 
writeToArchivedApplicationStore(ArchivedApplication archivedApplica
         }
     }
 
+    private CompletableFuture<?> 
registerGloballyTerminatedApplicationInApplicationResultStore(
+            ArchivedApplication application) {
+        final ApplicationID applicationId = application.getApplicationId();
+
+        return applicationResultStore
+                .hasCleanApplicationResultEntryAsync(applicationId)
+                .thenCompose(
+                        hasCleanResult -> {
+                            if (hasCleanResult) {
+                                log.warn(
+                                        "Application {} is already marked as 
clean but clean up was triggered again.",
+                                        applicationId);
+                                return FutureUtils.completedVoidFuture();
+                            }
+
+                            return applicationResultStore
+                                    
.hasDirtyApplicationResultEntryAsync(applicationId)
+                                    .thenCompose(
+                                            hasDirtyResult -> {
+                                                if (hasDirtyResult) {
+                                                    return 
FutureUtils.completedVoidFuture();
+                                                }
+
+                                                return applicationResultStore
+                                                        
.createDirtyResultAsync(
+                                                                new 
ApplicationResultEntry(
+                                                                        
ApplicationResult
+                                                                               
 .createFrom(
+                                                                               
         application)));
+                                            });
+                        })
+                .handleAsync(
+                        (ignored, error) -> {
+                            if (error != null) {
+                                fatalErrorHandler.onFatalError(
+                                        new FlinkException(
+                                                String.format(
+                                                        "The application %s 
couldn't be marked as pre-cleanup finished in ApplicationResultStore.",
+                                                        applicationId),
+                                                error));
+                            }
+                            
applicationCreateDirtyResultFutures.get(applicationId).complete(null);
+                            return null;
+                        },
+                        getMainThreadExecutor());
+    }
+
+    private CompletableFuture<Void> removeApplication(
+            ApplicationID applicationId, Collection<JobID> jobs) {
+        return applicationResourceCleaner
+                .cleanupAsync(applicationId)
+                .thenCombine(
+                        FutureUtils.waitForAll(
+                                jobs.stream()
+                                        .map(jobMarkResultCleanFutures::get)
+                                        .collect(Collectors.toList())),
+                        (unused1, unused2) ->
+                                
applicationResultStore.markResultAsCleanAsync(applicationId))

Review Comment:
   Updated: Use `thenCompose` instead of `thenCombine` to properly handle 
futures that complete exceptionally.



-- 
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]

Reply via email to