WencongLiu commented on code in PR #22341:
URL: https://github.com/apache/flink/pull/22341#discussion_r1283018521


##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -1390,29 +1392,71 @@ private CompletableFuture<CleanupJobState> 
registerGloballyTerminatedJobInJobRes
                 "Job %s is in state %s which is not globally terminal.",
                 jobId,
                 terminalJobStatus);
-
-        ioExecutor.execute(
-                () -> {
-                    try {
-                        if (jobResultStore.hasCleanJobResultEntry(jobId)) {
-                            log.warn(
-                                    "Job {} is already marked as clean but 
clean up was triggered again.",
-                                    jobId);
-                        } else if 
(!jobResultStore.hasDirtyJobResultEntry(jobId)) {
-                            jobResultStore.createDirtyResult(
-                                    new JobResultEntry(
-                                            
JobResult.createFrom(archivedExecutionGraph)));
-                            log.info(
-                                    "Job {} has been registered for cleanup in 
the JobResultStore after reaching a terminal state.",
-                                    jobId);
-                        }
-                    } catch (IOException e) {
-                        writeFuture.completeExceptionally(e);
+        CompletableFuture<Boolean> shouldCheckDirtyJobResult =
+                jobResultStore
+                        .hasCleanJobResultEntryAsync(jobId)
+                        .handleAsync(
+                                (hasCleanJobResultEntry, throwable) -> {
+                                    if (throwable != null) {
+                                        
writeFuture.completeExceptionally(throwable);
+                                        return false;
+                                    } else {
+                                        if (hasCleanJobResultEntry) {
+                                            log.warn(
+                                                    "Job {} is already marked 
as clean but "
+                                                            + "clean up was 
triggered again.",
+                                                    jobId);
+                                            writeFuture.complete(null);
+                                            return false;
+                                        } else {
+                                            return true;
+                                        }
+                                    }
+                                });
+        shouldCheckDirtyJobResult.whenCompleteAsync(
+                (shouldCheck, throwable1) -> {
+                    if (throwable1 != null) {
+                        writeFuture.completeExceptionally(throwable1);
                         return;
                     }
-                    writeFuture.complete(null);
+                    if (shouldCheck) {
+                        jobResultStore
+                                .hasDirtyJobResultEntryAsync(jobId)
+                                .whenCompleteAsync(
+                                        (hasDirtyJobResultEntry, throwable2) 
-> {
+                                            if (throwable2 != null) {
+                                                
writeFuture.completeExceptionally(throwable2);
+                                                return;
+                                            }
+                                            if (!hasDirtyJobResultEntry) {
+                                                jobResultStore
+                                                        
.createDirtyResultAsync(
+                                                                new 
JobResultEntry(
+                                                                        
JobResult.createFrom(
+                                                                               
 archivedExecutionGraph)))
+                                                        .whenCompleteAsync(
+                                                                (unused, 
throwable3) -> {
+                                                                    if 
(throwable3 != null) {
+                                                                        
writeFuture
+                                                                               
 .completeExceptionally(
+                                                                               
         throwable3);
+                                                                        return;
+                                                                    }
+                                                                    log.info(
+                                                                            
"Job {} has been registered "
+                                                                               
     + "for cleanup in "
+                                                                               
     + "the JobResultStore "
+                                                                               
     + "after reaching a "
+                                                                               
     + "terminal state.",
+                                                                            
jobId);
+                                                                    
writeFuture.complete(null);
+                                                                });
+                                            } else {
+                                                writeFuture.complete(null);
+                                            }
+                                        });
+                    }

Review Comment:
   Fixed.



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