xuanyuanking commented on a change in pull request #24565: [SPARK-27665][Core]
Split fetch shuffle blocks protocol from OpenBlocks
URL: https://github.com/apache/spark/pull/24565#discussion_r284964236
##########
File path:
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/OneForOneBlockFetcher.java
##########
@@ -76,12 +80,73 @@ public OneForOneBlockFetcher(
TransportConf transportConf,
DownloadFileManager downloadFileManager) {
this.client = client;
- this.openMessage = new OpenBlocks(appId, execId, blockIds);
this.blockIds = blockIds;
this.listener = listener;
this.chunkCallback = new ChunkCallback();
this.transportConf = transportConf;
this.downloadFileManager = downloadFileManager;
+ if (blockIds.length == 0) {
+ throw new IllegalArgumentException("Zero-sized blockIds array");
+ }
+ if (isShuffleBlocks(blockIds)) {
+ this.message = createFetchShuffleBlocksMsg(appId, execId, blockIds);
+ } else {
+ this.message = new OpenBlocks(appId, execId, blockIds);
+ }
+ }
+
+ private boolean isShuffleBlocks(String[] blockIds) {
+ for (String blockId : blockIds) {
+ if (!blockId.startsWith("shuffle_")) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Analyze the pass in blockIds and create FetchShuffleBlocks message.
+ * The blockIds has been sorted by mapId and reduceId. It's produced in
+ * org.apache.spark.MapOutputTracker.convertMapStatuses.
+ */
+ private FetchShuffleBlocks createFetchShuffleBlocksMsg(
+ String appId, String execId, String[] blockIds) {
+ int shuffleId;
+ shuffleId = splitBlockId(blockIds[0])[0];
+ HashMap<Integer, ArrayList<Integer>> mapIdToReduceIds = new HashMap<>();
+ for (String blockId : blockIds) {
+ int[] blockIdParts = splitBlockId(blockId);
+ if (blockIdParts[0] != shuffleId) {
+ throw new IllegalArgumentException("Expected shuffleId=" + shuffleId +
+ ", got:" + blockId);
+ }
+ int mapId = blockIdParts[1];
+ if (!mapIdToReduceIds.containsKey(mapId)) {
+ mapIdToReduceIds.put(mapId, new ArrayList<>());
+ }
+ mapIdToReduceIds.get(mapId).add(blockIdParts[2]);
+ }
+ int[] mapIds;
+ mapIds = Ints.toArray(mapIdToReduceIds.keySet());
Review comment:
fddcd6c.
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]