You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/20 09:55:47 UTC

[GitHub] [flink] TanYuxin-tyx opened a new pull request, #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

TanYuxin-tyx opened a new pull request, #20320:
URL: https://github.com/apache/flink/pull/20320

   <!--
   *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
   
   Currently, the SortMergeResultPartitionReadScheduler always gets all active subpartition readers and read at most one data region for them. It is common that some subpartitions are requested before others and their region indexes are ahead of others. 
   
   If all region data of a subpartition can be read in one round, some subpartition readers will always be ahead of others which will cause random IO. 
   
   This patch fixes this case by polling one subpartition reader at a time.
   
   
   ## Brief change log
     - *Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially.*
   
   
   ## Verifying this change
   
   This change is already covered by existing tests, such as *SortMergeResultPartitionReadSchedulerTest*.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / **no**)
     - If yes, how is the feature documented? (**not applicable** / docs / JavaDocs / not documented)
   


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


[GitHub] [flink] flinkbot commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1190085113

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a830ee22681f80b0f556aee94ef63694fa110d44",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "a830ee22681f80b0f556aee94ef63694fa110d44",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a830ee22681f80b0f556aee94ef63694fa110d44 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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1198019040

   @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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1191498330

   @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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1191118892

   > @TanYuxin-tyx, thanks for your contribution, this bug-fix looks good to me overall. I left some comments, please take a look~
   
   @reswqa Thanks a lot for reviewing the PR, I have updated the code and fixed the comments.


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


[GitHub] [flink] reswqa commented on a diff in pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20320:
URL: https://github.com/apache/flink/pull/20320#discussion_r925823372


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -152,12 +160,34 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
 
     @Override
     public synchronized void run() {
-        Queue<SortMergeSubpartitionReader> availableReaders = getAvailableReaders();
-
-        Queue<MemorySegment> buffers = allocateBuffers(availableReaders);
+        Set<SortMergeSubpartitionReader> finishedReaders = new HashSet<>();
+        Queue<MemorySegment> buffers;
+        try {
+            buffers = allocateBuffers();
+        } catch (Throwable throwable) {
+            // fail all pending subpartition readers immediately if any exception occurs
+            LOG.error("Failed to request buffers for data reading.", throwable);
+            failSubpartitionReaders(getAllReaders(), throwable);

Review Comment:
   `release` and `releaseSubpartitionReader` should take care of `sortedReaders ` also. These two method will add reader to `failedReaders` set, we should filter out useless readers as soon as possible. For example, may not be the best solution, we can add check to `getNextReaderToRead`, when the polled reader contains in `failedReaders`, ignore it and poll next until meet the reader not failed. But `removeFinishedAndFailedReaders` will clear `failedReaders`, It is possible that some failed readers have not been polled from `sortedReaders` in this round of scheduling, we can remove the failed reader from `failedReaders` in `getNextReaderToRead` every time polled reader is failed.



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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1191110379

   @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


[GitHub] [flink] reswqa commented on a diff in pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20320:
URL: https://github.com/apache/flink/pull/20320#discussion_r925823372


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -152,12 +160,34 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
 
     @Override
     public synchronized void run() {
-        Queue<SortMergeSubpartitionReader> availableReaders = getAvailableReaders();
-
-        Queue<MemorySegment> buffers = allocateBuffers(availableReaders);
+        Set<SortMergeSubpartitionReader> finishedReaders = new HashSet<>();
+        Queue<MemorySegment> buffers;
+        try {
+            buffers = allocateBuffers();
+        } catch (Throwable throwable) {
+            // fail all pending subpartition readers immediately if any exception occurs
+            LOG.error("Failed to request buffers for data reading.", throwable);
+            failSubpartitionReaders(getAllReaders(), throwable);

Review Comment:
   `release` and `releaseSubpartitionReader` should take care of `sortedReaders ` also. These two method will add reader to `failedReaders` set, we should filter out useless readers as soon as possible. For example, may not be the best solution, we can add check to `getNextReaderToRead`, when the polled reader contains in `failedReaders`, ignore it and poll next until meet the reader not failed. But `removeFinishedAndFailedReaders` will clear `failedReaders`, It is possible that some failed readers have not been polled from `sortedReaders` in this round of scheduling. We can remove the failed reader from `failedReaders` in `getNextReaderToRead` every time polled reader is failed, instead of in `removeFinishedAndFailedReaders`.



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


[GitHub] [flink] reswqa commented on a diff in pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20320:
URL: https://github.com/apache/flink/pull/20320#discussion_r925823372


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -152,12 +160,34 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
 
     @Override
     public synchronized void run() {
-        Queue<SortMergeSubpartitionReader> availableReaders = getAvailableReaders();
-
-        Queue<MemorySegment> buffers = allocateBuffers(availableReaders);
+        Set<SortMergeSubpartitionReader> finishedReaders = new HashSet<>();
+        Queue<MemorySegment> buffers;
+        try {
+            buffers = allocateBuffers();
+        } catch (Throwable throwable) {
+            // fail all pending subpartition readers immediately if any exception occurs
+            LOG.error("Failed to request buffers for data reading.", throwable);
+            failSubpartitionReaders(getAllReaders(), throwable);

Review Comment:
   `release` and `releaseSubpartitionReader` should take care of `sortedReaders ` also.



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


[GitHub] [flink] wsry merged pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
wsry merged PR #20320:
URL: https://github.com/apache/flink/pull/20320


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


[GitHub] [flink] reswqa commented on a diff in pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20320:
URL: https://github.com/apache/flink/pull/20320#discussion_r925818232


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -152,12 +160,34 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
 
     @Override
     public synchronized void run() {
-        Queue<SortMergeSubpartitionReader> availableReaders = getAvailableReaders();
-
-        Queue<MemorySegment> buffers = allocateBuffers(availableReaders);
+        Set<SortMergeSubpartitionReader> finishedReaders = new HashSet<>();
+        Queue<MemorySegment> buffers;
+        try {
+            buffers = allocateBuffers();
+        } catch (Throwable throwable) {
+            // fail all pending subpartition readers immediately if any exception occurs
+            LOG.error("Failed to request buffers for data reading.", throwable);
+            failSubpartitionReaders(getAllReaders(), throwable);

Review Comment:
   If a failed reader not removed from `sortedBuffers` in time, It can only be removed after the next poll, but this failed reader will read data from disk int that case, which is an unnecessary extra overhead. IMO, we need clear `sortedReaders`  when `allocateBuffers` throw exception.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -283,13 +284,26 @@ private void mayNotifyReleased() {
         }
     }
 
-    private Queue<SortMergeSubpartitionReader> getAvailableReaders() {
+    private Queue<SortMergeSubpartitionReader> getAllReaders() {
         synchronized (lock) {
             if (isReleased) {
                 return new ArrayDeque<>();
             }
+            return new ArrayDeque<>(allReaders);
+        }
+    }
 
-            return new PriorityQueue<>(allReaders);
+    @Nullable
+    private SortMergeSubpartitionReader getNextReaderToRead(

Review Comment:
   ```suggestion
       private SortMergeSubpartitionReader addPreviousAndGetNextReader(
   ```



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -152,12 +160,34 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
 
     @Override
     public synchronized void run() {
-        Queue<SortMergeSubpartitionReader> availableReaders = getAvailableReaders();
-
-        Queue<MemorySegment> buffers = allocateBuffers(availableReaders);
+        Set<SortMergeSubpartitionReader> finishedReaders = new HashSet<>();
+        Queue<MemorySegment> buffers;
+        try {
+            buffers = allocateBuffers();
+        } catch (Throwable throwable) {
+            // fail all pending subpartition readers immediately if any exception occurs
+            LOG.error("Failed to request buffers for data reading.", throwable);
+            failSubpartitionReaders(getAllReaders(), throwable);

Review Comment:
   `release` and `releaseSubpartitionReader` should take care of `sortedReaders ` also. These two method will add reader to `failedReaders` set, I suggest add check to `getNextReaderToRead`, when the polled reader contains in `failedReaders`, we can ignore it and poll next until meet the reader not failed.



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


[GitHub] [flink] TanYuxin-tyx commented on a diff in pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on code in PR #20320:
URL: https://github.com/apache/flink/pull/20320#discussion_r926313613


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -152,12 +160,34 @@ class SortMergeResultPartitionReadScheduler implements Runnable, BufferRecycler
 
     @Override
     public synchronized void run() {
-        Queue<SortMergeSubpartitionReader> availableReaders = getAvailableReaders();
-
-        Queue<MemorySegment> buffers = allocateBuffers(availableReaders);
+        Set<SortMergeSubpartitionReader> finishedReaders = new HashSet<>();
+        Queue<MemorySegment> buffers;
+        try {
+            buffers = allocateBuffers();
+        } catch (Throwable throwable) {
+            // fail all pending subpartition readers immediately if any exception occurs
+            LOG.error("Failed to request buffers for data reading.", throwable);
+            failSubpartitionReaders(getAllReaders(), throwable);

Review Comment:
   @reswqa Thanks for helping review. Good point. 
   
   In order to clear the reader in `sortedBuffers` in time, I added a check whether the reader is in `failedReaders` in the method `addPreviousAndGetNextReader`. 
   In addtion, when `allReaders` is empty, the `sortedBuffers` will be cleared in `removeFinishedAndFailedReaders`.



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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1199042877

   @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


[GitHub] [flink] TanYuxin-tyx commented on a diff in pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on code in PR #20320:
URL: https://github.com/apache/flink/pull/20320#discussion_r926310001


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/SortMergeResultPartitionReadScheduler.java:
##########
@@ -283,13 +284,26 @@ private void mayNotifyReleased() {
         }
     }
 
-    private Queue<SortMergeSubpartitionReader> getAvailableReaders() {
+    private Queue<SortMergeSubpartitionReader> getAllReaders() {
         synchronized (lock) {
             if (isReleased) {
                 return new ArrayDeque<>();
             }
+            return new ArrayDeque<>(allReaders);
+        }
+    }
 
-            return new PriorityQueue<>(allReaders);
+    @Nullable
+    private SortMergeSubpartitionReader getNextReaderToRead(

Review Comment:
   OK, renamed it.



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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1191438366

   @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


[GitHub] [flink] TanYuxin-tyx commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
TanYuxin-tyx commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1199057289

   @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


[GitHub] [flink] wsry commented on pull request #20320: [FLINK-28519][network] Fix the bug that SortMergeResultPartitionReadScheduler may not read data sequentially

Posted by GitBox <gi...@apache.org>.
wsry commented on PR #20320:
URL: https://github.com/apache/flink/pull/20320#issuecomment-1199191376

   @TanYuxin-tyx Thanks for the change and review from @reswqa . LGTM.


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