LuciferYang commented on code in PR #37843:
URL: https://github.com/apache/spark/pull/37843#discussion_r967635743


##########
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/OneForOneBlockFetcher.java:
##########
@@ -113,10 +113,28 @@ public OneForOneBlockFetcher(
    * @return whether the array contains only shuffle block IDs
    */
   private boolean areShuffleBlocksOrChunks(String[] blockIds) {
-    if (Arrays.stream(blockIds).anyMatch(blockId -> 
!blockId.startsWith(SHUFFLE_BLOCK_PREFIX))) {
+    if (isAnyBlockNotStartWithShuffleBlockPrefix(blockIds)) {
       // It comes here because there is a blockId which doesn't have 
"shuffle_" prefix so we
       // check if all the block ids are shuffle chunk Ids.
-      return Arrays.stream(blockIds).allMatch(blockId -> 
blockId.startsWith(SHUFFLE_CHUNK_PREFIX));
+      return isAllBlocksStartWithShuffleChunkPrefix(blockIds);
+    }
+    return true;
+  }
+
+  private boolean isAnyBlockNotStartWithShuffleBlockPrefix(String[] blockIds) {
+    for (String blockId : blockIds) {
+      if (!blockId.startsWith(SHUFFLE_BLOCK_PREFIX)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private boolean isAllBlocksStartWithShuffleChunkPrefix(String[] blockIds) {

Review Comment:
   Compare 
   
   ```
   public static boolean allMatchUseStreamApi(long[] input, long target) {
           return Arrays.stream(input).allMatch(l  -> l > target);
   }
   ```
   
   and 
   
   ```
   public static boolean allMatchUseLoopApi(long[] input, long target) {
           for (long l : input) {
               if (l <= target) {
                   return false;
               }
           }
           return true;
       }
   ```
   
   test with:
   
   - input: (2 to 2), target: 1
   - input: (2 to 5), target:1
   - input: (2 to 10), target:1
   - input: (2 to 20), target:1
   - input: (2 to 50), target:1
   - input: (2 to 100), target:1
   - input: (2 to 500), target:1
   - input: (2 to 1000), target:1
   - input: (2 to 10000), target:1



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to