You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "eemario (via GitHub)" <gi...@apache.org> on 2025/04/21 11:37:51 UTC

[PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

eemario opened a new pull request, #26489:
URL: https://github.com/apache/flink/pull/26489

   …all job termination futures complete
   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   
   *This pull request makes the cluster shutdown after all job termination futures complete in application mode, so that the ExecutionGraphInfo archiving and job cleanup can be finished.*
   
   
   ## Brief change log
   
     - *The Dispatcher completes the shutdown future after all job termination futures complete.*
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follow [the conventions for tests defined in our code quality guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
   
   
   This change added tests and can be verified as follows:
   
     - *Added test that validates that the shutdown future completes after all job termination futures complete*
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
   


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "eemario (via GitHub)" <gi...@apache.org>.
eemario commented on PR #26489:
URL: https://github.com/apache/flink/pull/26489#issuecomment-2820638875

   @flinkbot run azure


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2053295509


##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -1256,7 +1268,8 @@ private void setClientHeartbeatTimeoutForInitializedJob() {
         }
     }
 
-    private void registerJobManagerRunnerTerminationFuture(
+    @VisibleForTesting
+    public void registerJobManagerRunnerTerminationFuture(

Review Comment:
   can be package-private



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2052653921


##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -1093,13 +1093,25 @@ public CompletableFuture<String> stopWithSavepointAndGetLocation(
 
     @Override
     public CompletableFuture<Acknowledge> shutDownCluster() {
-        return shutDownCluster(ApplicationStatus.SUCCEEDED);
+        return internalShutDownCluster(ApplicationStatus.SUCCEEDED, false);
     }
 
     @Override
     public CompletableFuture<Acknowledge> shutDownCluster(
             final ApplicationStatus applicationStatus) {
-        shutDownFuture.complete(applicationStatus);
+        return internalShutDownCluster(applicationStatus, true);
+    }
+
+    private CompletableFuture<Acknowledge> internalShutDownCluster(
+            final ApplicationStatus applicationStatus,
+            final boolean waitForAllJobTerminationFutures) {
+        final CompletableFuture<Void> allJobsTerminationFuture =
+                waitForAllJobTerminationFutures
+                        ? FutureUtils.completeAll(jobManagerRunnerTerminationFutures.values())
+                        : CompletableFuture.completedFuture(null);
+
+        FutureUtils.runAfterwards(
+                allJobsTerminationFuture, () -> shutDownFuture.complete(applicationStatus));
         return CompletableFuture.completedFuture(Acknowledge.get());

Review Comment:
   minor question: Why this future directly return as a completed future instead of wait for the completion of allJobsTerminationFuture?



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "eemario (via GitHub)" <gi...@apache.org>.
eemario commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2053886495


##########
flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java:
##########
@@ -1041,6 +1041,29 @@ public void testShutDownClusterShouldCompleteShutDownFuture() throws Exception {
         dispatcher.getShutDownFuture().get();
     }
 
+    @Test
+    public void testShutDownFutureCompletesAfterJobTerminationFutures() throws Exception {

Review Comment:
   Thanks @RocMarshal. Currently all tests in `DispatcherTest` are still using JUnit 4. It's better to stick with the existing format for now and the tests in `DispatcherTest` can be migrated to JUnit 5 in a separate PR.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee merged PR #26489:
URL: https://github.com/apache/flink/pull/26489


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "RocMarshal (via GitHub)" <gi...@apache.org>.
RocMarshal commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2055102600


##########
flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java:
##########
@@ -1041,6 +1041,29 @@ public void testShutDownClusterShouldCompleteShutDownFuture() throws Exception {
         dispatcher.getShutDownFuture().get();
     }
 
+    @Test
+    public void testShutDownFutureCompletesAfterJobTerminationFutures() throws Exception {

Review Comment:
   Thanks for the clarify.
   That sounds good to me ! 👍 



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "JunRuiLee (via GitHub)" <gi...@apache.org>.
JunRuiLee commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2052656518


##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -1596,6 +1608,12 @@ CompletableFuture<Void> getJobTerminationFuture(JobID jobId) {
                 jobId, CompletableFuture.completedFuture(null));
     }
 
+    @VisibleForTesting
+    CompletableFuture<Void> addJobTerminationFuture(

Review Comment:
   We could reuse the method registerJobManagerRunnerTerminationFuture and annotate it as VisibleForTesting.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -1093,13 +1093,25 @@ public CompletableFuture<String> stopWithSavepointAndGetLocation(
 
     @Override
     public CompletableFuture<Acknowledge> shutDownCluster() {
-        return shutDownCluster(ApplicationStatus.SUCCEEDED);
+        return internalShutDownCluster(ApplicationStatus.SUCCEEDED, false);
     }
 
     @Override
     public CompletableFuture<Acknowledge> shutDownCluster(
             final ApplicationStatus applicationStatus) {
-        shutDownFuture.complete(applicationStatus);
+        return internalShutDownCluster(applicationStatus, true);
+    }
+
+    private CompletableFuture<Acknowledge> internalShutDownCluster(
+            final ApplicationStatus applicationStatus,
+            final boolean waitForAllJobTerminationFutures) {
+        final CompletableFuture<Void> allJobsTerminationFuture =
+                waitForAllJobTerminationFutures
+                        ? FutureUtils.completeAll(jobManagerRunnerTerminationFutures.values())
+                        : CompletableFuture.completedFuture(null);
+
+        FutureUtils.runAfterwards(
+                allJobsTerminationFuture, () -> shutDownFuture.complete(applicationStatus));
         return CompletableFuture.completedFuture(Acknowledge.get());

Review Comment:
   minor questions: Should this future wait for the completion of allJobsTerminationFuture, or should it directly return as a completed future?



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "eemario (via GitHub)" <gi...@apache.org>.
eemario commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2053286838


##########
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java:
##########
@@ -1093,13 +1093,25 @@ public CompletableFuture<String> stopWithSavepointAndGetLocation(
 
     @Override
     public CompletableFuture<Acknowledge> shutDownCluster() {
-        return shutDownCluster(ApplicationStatus.SUCCEEDED);
+        return internalShutDownCluster(ApplicationStatus.SUCCEEDED, false);
     }
 
     @Override
     public CompletableFuture<Acknowledge> shutDownCluster(
             final ApplicationStatus applicationStatus) {
-        shutDownFuture.complete(applicationStatus);
+        return internalShutDownCluster(applicationStatus, true);
+    }
+
+    private CompletableFuture<Acknowledge> internalShutDownCluster(
+            final ApplicationStatus applicationStatus,
+            final boolean waitForAllJobTerminationFutures) {
+        final CompletableFuture<Void> allJobsTerminationFuture =
+                waitForAllJobTerminationFutures
+                        ? FutureUtils.completeAll(jobManagerRunnerTerminationFutures.values())
+                        : CompletableFuture.completedFuture(null);
+
+        FutureUtils.runAfterwards(
+                allJobsTerminationFuture, () -> shutDownFuture.complete(applicationStatus));
         return CompletableFuture.completedFuture(Acknowledge.get());

Review Comment:
   My understanding is that `shutDownCluster` method returns a CompletableFuture<Acknowledge> to indicate that the shutdown request has been accepted, rather than any operation has been completed. The actual shutdown operation is performed asynchronously to avoid blocking the caller.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "RocMarshal (via GitHub)" <gi...@apache.org>.
RocMarshal commented on code in PR #26489:
URL: https://github.com/apache/flink/pull/26489#discussion_r2053723660


##########
flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java:
##########
@@ -1041,6 +1041,29 @@ public void testShutDownClusterShouldCompleteShutDownFuture() throws Exception {
         dispatcher.getShutDownFuture().get();
     }
 
+    @Test
+    public void testShutDownFutureCompletesAfterJobTerminationFutures() throws Exception {

Review Comment:
   ```suggestion
       void testShutDownFutureCompletesAfterJobTerminationFutures() throws Exception {
   ```



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "eemario (via GitHub)" <gi...@apache.org>.
eemario commented on PR #26489:
URL: https://github.com/apache/flink/pull/26489#issuecomment-2820955027

   @flinkbot run azure


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "eemario (via GitHub)" <gi...@apache.org>.
eemario commented on PR #26489:
URL: https://github.com/apache/flink/pull/26489#issuecomment-2820638665

   Thanks @JunRuiLee  !


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37697][runtime] Fix application mode cluster shut down before … [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #26489:
URL: https://github.com/apache/flink/pull/26489#issuecomment-2818252037

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "645739ae4eb8d9fad870136de6a4f66dfb48607f",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "645739ae4eb8d9fad870136de6a4f66dfb48607f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 645739ae4eb8d9fad870136de6a4f66dfb48607f UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org