tillrohrmann commented on a change in pull request #7757: [FLINK-11630] 
Triggers the termination of all running Tasks when shutting down TaskExecutor
URL: https://github.com/apache/flink/pull/7757#discussion_r285999078
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
 ##########
 @@ -348,20 +353,41 @@ private void 
handleStartTaskExecutorServicesException(Exception e) throws Except
                resourceManagerHeartbeatManager.stop();
 
                try {
-                       stopTaskExecutorServices();
+                       stopServicesBeforeTasksCompletion();
                } catch (Exception e) {
                        throwable = ExceptionUtils.firstOrSuppressed(e, 
throwable);
                }
 
                if (throwable != null) {
                        return FutureUtils.completedExceptionally(new 
FlinkException("Error while shutting the TaskExecutor down.", throwable));
                } else {
-                       log.info("Stopped TaskExecutor {}.", getAddress());
-                       return CompletableFuture.completedFuture(null);
+                       return 
FutureUtils.waitForAll(taskCompletionFutures).thenRun(() -> {
+                               try {
+                                       stopServicesAfterTasksCompletion();
+                               } catch (Exception e) {
+                                       throw new FlinkRuntimeException("Error 
while shutting the TaskExecutor down.", e);
+                               }
+                               log.info("Stopped TaskExecutor {}.", 
getAddress());
+                       });
                }
        }
 
-       private void stopTaskExecutorServices() throws Exception {
+       private List<CompletableFuture<Void>> failTasks(JobID jobID, Throwable 
cause) {
+               List<CompletableFuture<Void>> taskCompletionFutures = new 
ArrayList<>();
+               Iterator<Task> tasks = taskSlotTable.getTasks(jobID);
+               while (tasks.hasNext()) {
+                       try {
+                               Task task = tasks.next();
+                               task.failExternally(cause);
+                               
taskCompletionFutures.add(task.getTaskCompletionFuture());
+                       } catch (Throwable t) {
+                               
taskCompletionFutures.add(FutureUtils.completedExceptionally(t));
+                       }
+        }
+        return taskCompletionFutures;
+       }
+
+       private void stopServicesBeforeTasksCompletion() throws Exception {
 
 Review comment:
   Why did you separate the service shutdown into two stages? Can't we simply 
stop all services after the `Tasks` have been terminated?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to