yucai commented on a change in pull request #19788: [SPARK-9853][Core] Optimize 
shuffle fetch of contiguous partition IDs
URL: https://github.com/apache/spark/pull/19788#discussion_r249518782
 
 

 ##########
 File path: 
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalShuffleBlockResolver.java
 ##########
 @@ -161,22 +161,69 @@ public void registerExecutor(
     executors.put(fullId, executorInfo);
   }
 
+  // For testing
+  public ManagedBuffer getBlockData(
+      String appId,
+      String execId,
+      int shuffleId,
+      int mapId,
+      int reduceId) {
+    return getBlockData(appId, execId, shuffleId, mapId, reduceId, 1);
+  }
+
   /**
-   * Obtains a FileSegmentManagedBuffer from (shuffleId, mapId, reduceId). We 
make assumptions
-   * about how the hash and sort based shuffles store their data.
+   * Obtains a FileSegmentManagedBuffer from (shuffleId, mapId, reduceId, 
numBlocks). We make
+   * assumptions about how the hash and sort based shuffles store their data.
    */
   public ManagedBuffer getBlockData(
       String appId,
       String execId,
       int shuffleId,
       int mapId,
-      int reduceId) {
+      int reduceId,
+      int numBlocks) {
     ExecutorShuffleInfo executor = executors.get(new AppExecId(appId, execId));
     if (executor == null) {
       throw new RuntimeException(
         String.format("Executor is not registered (appId=%s, execId=%s)", 
appId, execId));
     }
-    return getSortBasedShuffleBlockData(executor, shuffleId, mapId, reduceId);
+    return getSortBasedShuffleBlockData(executor, shuffleId, mapId, reduceId, 
numBlocks);
+  }
+
+  static public boolean isShuffleBlock(String[] blockIdParts) {
+    // length == 4: ShuffleBlockId
+    // length == 5: ShuffleBlockBatchId
+    return (blockIdParts.length == 4 || blockIdParts.length == 5) &&
+      blockIdParts[0].equals("shuffle");
+  }
+
+  static public int[] getBlockIdParts(String blockId) {
+    String[] blockIdParts = blockId.split("_");
+    if (!isShuffleBlock(blockIdParts)) {
+      throw new IllegalArgumentException("Unexpected shuffle block id format: 
" + blockId);
+    }
+    return new int[] { Integer.parseInt(blockIdParts[2]), 
Integer.parseInt(blockIdParts[3]) };
+  }
+
+  static public ArrayList<ArrayList<int[]>> 
mergeContinuousShuffleBlockIds(String[] blockIds) {
+    ArrayList<int[]> shuffleBlockIds = new ArrayList<>();
+    ArrayList<ArrayList<int[]>> arrayShuffleBlockIds = new ArrayList<>();
 
 Review comment:
   Oh, seems like numBlocks is not enough, which includes possible zero size 
blocks.
   And this function will be reused in `OneForOneBlockFetcher`, there needs 
real size infor.
   ```
     private void initShuffleBlockIdIndices(String[] blockIds) {
       ArrayList<ArrayList<int[]>> arrayShuffleBlockIds =
         ExternalShuffleBlockResolver.mergeContinuousShuffleBlockIds(blockIds);
       assert(arrayShuffleBlockIds.size() == streamHandle.numChunks);
       blockIdIndices = new int[arrayShuffleBlockIds.size() + 1];
       blockIdIndices[0] = 0;
       for (int i = 0; i < arrayShuffleBlockIds.size(); i++) {
         blockIdIndices[i + 1] = blockIdIndices[i] + 
arrayShuffleBlockIds.get(i).size();
       }
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

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

Reply via email to