Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/16989#discussion_r117172780
--- Diff:
core/src/main/scala/org/apache/spark/storage/ShuffleBlockFetcherIterator.scala
---
@@ -175,33 +197,54 @@ final class ShuffleBlockFetcherIterator(
val sizeMap = req.blocks.map { case (blockId, size) =>
(blockId.toString, size) }.toMap
val remainingBlocks = new HashSet[String]() ++= sizeMap.keys
val blockIds = req.blocks.map(_._1.toString)
-
val address = req.address
- shuffleClient.fetchBlocks(address.host, address.port,
address.executorId, blockIds.toArray,
- new BlockFetchingListener {
- override def onBlockFetchSuccess(blockId: String, buf:
ManagedBuffer): Unit = {
- // Only add the buffer to results queue if the iterator is not
zombie,
- // i.e. cleanup() has not been called yet.
- ShuffleBlockFetcherIterator.this.synchronized {
- if (!isZombie) {
- // Increment the ref count because we need to pass this to a
different thread.
- // This needs to be released after use.
- buf.retain()
- remainingBlocks -= blockId
- results.put(new SuccessFetchResult(BlockId(blockId),
address, sizeMap(blockId), buf,
- remainingBlocks.isEmpty))
- logDebug("remainingBlocks: " + remainingBlocks)
- }
+
+ val blockFetchingListener = new BlockFetchingListener {
+ override def onBlockFetchSuccess(blockId: String, buf:
ManagedBuffer): Unit = {
+ // Only add the buffer to results queue if the iterator is not
zombie,
+ // i.e. cleanup() has not been called yet.
+ ShuffleBlockFetcherIterator.this.synchronized {
+ if (!isZombie) {
+ // Increment the ref count because we need to pass this to a
different thread.
+ // This needs to be released after use.
+ buf.retain()
+ remainingBlocks -= blockId
+ results.put(new SuccessFetchResult(BlockId(blockId), address,
sizeMap(blockId), buf,
+ remainingBlocks.isEmpty))
+ logDebug("remainingBlocks: " + remainingBlocks)
}
- logTrace("Got remote block " + blockId + " after " +
Utils.getUsedTimeMs(startTime))
}
+ logTrace("Got remote block " + blockId + " after " +
Utils.getUsedTimeMs(startTime))
+ }
- override def onBlockFetchFailure(blockId: String, e: Throwable):
Unit = {
- logError(s"Failed to get block(s) from
${req.address.host}:${req.address.port}", e)
- results.put(new FailureFetchResult(BlockId(blockId), address, e))
- }
+ override def onBlockFetchFailure(blockId: String, e: Throwable):
Unit = {
+ logError(s"Failed to get block(s) from
${req.address.host}:${req.address.port}", e)
+ results.put(new FailureFetchResult(BlockId(blockId), address, e))
}
- )
+ }
+
+ // Shuffle remote blocks to disk when the request is too large or
local memory shortage.
+ val fetchToDisk = if (req.size > maxReqSizeShuffleToMem) {
+ true
+ } else {
+ val acquired = acquireMemory(req.size)
+ if (acquired < req.size) {
+ freeMemory(acquired)
+ true
+ } else {
+ false
+ }
+ }
+
+ if (fetchToDisk) {
+ shuffleClient.fetchBlocks(address.host, address.port,
address.executorId, blockIds.toArray,
+ blockFetchingListener,
+ blockIds.map(bId =>
blockManager.diskBlockManager.getFile(s"remote-$bId")).toArray)
--- End diff --
There's technically nothing which prohibits two tasks from fetching the
same shuffle block. This doesn't happen in practice today, but there's nothing
in Spark's shuffle interfaces which preclude an
all-map-outputs-to-all-reduce-tasks broadcast. Given this, I'd prefer to be
defensive and assign a unique temporary file name which incorporates the
blockId but also includes something unique (such as the task attempt number).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]