Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions core/src/main/scala/org/apache/spark/storage/BlockManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,26 @@ private[spark] class BlockManager(
bytes: ByteBuffer,
serializer: Serializer = defaultSerializer): Iterator[Any] = {
bytes.rewind()
val stream = wrapForCompression(blockId, new ByteBufferInputStream(bytes, true))
serializer.newInstance().deserializeStream(stream).asIterator

def getIterator = {
val stream = wrapForCompression(blockId, new ByteBufferInputStream(bytes, true))
serializer.newInstance().deserializeStream(stream).asIterator
}

if (blockId.isShuffle) {
// Reducer may need to read many local shuffle blocks and will wrap them into Iterators
// at the beginning. The wrapping will cost some memory (compression instance
// initialization, etc.). Reducer read shuffle blocks one by one so we could do the
// wrapping lazily to save memory.
class LazyProxyIterator(f: => Iterator[Any]) extends Iterator[Any] {
lazy val proxy = f
override def hasNext: Boolean = proxy.hasNext
override def next(): Any = proxy.next()
}
new LazyProxyIterator(getIterator)
} else {
getIterator
}
}

def stop() {
Expand Down