Github user massie commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6423#discussion_r32076483
  
    --- Diff: 
core/src/main/scala/org/apache/spark/shuffle/hash/HashShuffleReader.scala ---
    @@ -33,17 +34,54 @@ private[spark] class HashShuffleReader[K, C](
         "Hash shuffle currently only supports fetching one partition")
     
       private val dep = handle.dependency
    +  private val blockManager = SparkEnv.get.blockManager
     
       /** Read the combined key-values for this reduce task */
       override def read(): Iterator[Product2[K, C]] = {
    +    val blockStreams = BlockStoreShuffleFetcher.fetchBlockStreams(
    +      handle.shuffleId, startPartition, context)
    +
    +    // Wrap the streams for compression based on configuration
    +    val wrappedStreams = blockStreams.map { case (blockId, inputStream) =>
    +      blockManager.wrapForCompression(blockId, inputStream)
    +    }
    +
         val ser = Serializer.getSerializer(dep.serializer)
    -    val iter = BlockStoreShuffleFetcher.fetch(handle.shuffleId, 
startPartition, context, ser)
    +    val serializerInstance = ser.newInstance()
    +
    +    // Create a key/value iterator for each stream
    +    val recordIterator = wrappedStreams.flatMap { wrappedStream =>
    +      val kvIter = 
serializerInstance.deserializeStream(wrappedStream).asKeyValueIterator
    +      CompletionIterator[(Any, Any), Iterator[(Any, Any)]](kvIter, {
    +        // Close the stream once all the records have been read from it to 
free underlying
    +        // ManagedBuffer as soon as possible. Note that in case of task 
failure, the task's
    +        // TaskCompletionListener will make sure this is released.
    +        wrappedStream.close()
    --- End diff --
    
    @kayousterhout Actually, I wasn't aware that `asKeyValueIterator` returned 
a `NextIterator` which closed the underlying input stream. Thanks for pointing 
that out to me.
    
    The `BufferReleasingInputStream.close()` is idempotent so it doesn't hurt 
to call it twice (I've also updated the unit tests to assure this is the case). 
The Parquet Shuffle Manager I'm writing doesn't use any Spark `Serializer` so 
that's why I noticed I needed to `close()` in the reader.
    
    I'll remove the `CompletionIterator` unless you think otherwise.


---
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]

Reply via email to