File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
core/src/main/scala/org/apache/spark Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -90,18 +90,19 @@ private[spark] class TorrentBroadcast[T: ClassTag](
90
90
private def readBlocks (): Array [ByteBuffer ] = {
91
91
// Fetch chunks of data. Note that all these chunks are stored in the BlockManager and reported
92
92
// to the driver, so other executors can pull these chunks from this executor as well.
93
- var numBlocksAvailable = 0
94
93
val blocks = new Array [ByteBuffer ](numBlocks)
95
94
96
95
for (pid <- Random .shuffle(Seq .range(0 , numBlocks))) {
97
96
val pieceId = BroadcastBlockId (id, " piece" + pid)
98
- SparkEnv .get.blockManager.getRemoteBytes(pieceId) match {
99
- case Some (x) =>
100
- blocks(pid) = x.asInstanceOf [ByteBuffer ]
101
- numBlocksAvailable += 1
97
+ // Note that we use getBytes rather than getRemoteBytes here because there is a chance
98
+ // that previous attempts to fetch the broadcast blocks have already fetched some of the
99
+ // blocks. In that case, some blocks would be available locally (on this executor).
100
+ SparkEnv .get.blockManager.getBytes(pieceId) match {
101
+ case Some (block) =>
102
+ blocks(pid) = block
102
103
SparkEnv .get.blockManager.putBytes(
103
104
pieceId,
104
- blocks(pid) ,
105
+ block ,
105
106
StorageLevel .MEMORY_AND_DISK_SER ,
106
107
tellMaster = true )
107
108
Original file line number Diff line number Diff line change @@ -517,6 +517,16 @@ private[spark] class BlockManager(
517
517
None
518
518
}
519
519
520
+ def getBytes (blockId : BlockId ): Option [ByteBuffer ] = {
521
+ val local = getLocalBytes(blockId)
522
+ if (local.isDefined) {
523
+ local
524
+ } else {
525
+ val remote = getRemoteBytes(blockId)
526
+ remote
527
+ }
528
+ }
529
+
520
530
/**
521
531
* Get a block from the block manager (either local or remote).
522
532
*/
You can’t perform that action at this time.
0 commit comments