XComp commented on a change in pull request #18189: URL: https://github.com/apache/flink/pull/18189#discussion_r780321496
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/runner/SessionDispatcherLeaderProcess.java ########## @@ -92,34 +99,61 @@ private void startServices() { } } - private void createDispatcherIfRunning(Collection<JobGraph> jobGraphs) { - runIfStateIs(State.RUNNING, () -> createDispatcher(jobGraphs)); + private void createDispatcherIfRunning( + Collection<JobGraph> jobGraphs, Collection<JobResult> globallyTerminatedJobs) { + runIfStateIs(State.RUNNING, () -> createDispatcher(jobGraphs, globallyTerminatedJobs)); } - private void createDispatcher(Collection<JobGraph> jobGraphs) { + private void createDispatcher( + Collection<JobGraph> jobGraphs, Collection<JobResult> globallyTerminatedJobs) { final DispatcherGatewayService dispatcherService = dispatcherGatewayServiceFactory.create( - DispatcherId.fromUuid(getLeaderSessionId()), jobGraphs, jobGraphStore); + DispatcherId.fromUuid(getLeaderSessionId()), + jobGraphs, + globallyTerminatedJobs, + jobGraphStore, + jobResultStore); completeDispatcherSetup(dispatcherService); } - private CompletableFuture<Collection<JobGraph>> recoverJobsAsync() { - return CompletableFuture.supplyAsync(this::recoverJobsIfRunning, ioExecutor); + private CompletableFuture<Void> + createDispatcherBasedOnRecoveredJobGraphsAndGloballyTerminatedJobs() { + return CompletableFuture.supplyAsync( + this::getGloballyCompletedJobResultsIfRunning, ioExecutor) + .thenCompose( + globallyTerminatedJobs -> + CompletableFuture.supplyAsync( + () -> + this.recoverJobsIfRunning( + globallyTerminatedJobs.stream() + .map(JobResult::getJobId) + .collect( + Collectors + .toSet())), + ioExecutor) + .thenAccept( + jobGraphs -> + createDispatcherIfRunning( + jobGraphs, globallyTerminatedJobs)) + .handle(this::onErrorIfRunning)); Review comment: I'm wondering whether the `dirtyJobsFuture.thenApplyAsync` is necessary here. Wouldn't it be executed in the same thread pool as the previous `supplyAsync` since both are chained together? -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org