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

    https://github.com/apache/spark/pull/15935#discussion_r88969131
  
    --- Diff: 
core/src/main/scala/org/apache/spark/broadcast/TorrentBroadcast.scala ---
    @@ -85,10 +86,21 @@ private[spark] class TorrentBroadcast[T: ClassTag](obj: 
T, id: Long)
       /** Total number of blocks this broadcast variable contains. */
       private val numBlocks: Int = writeBlocks(obj)
     
    +  /** The checksum for all the blocks. */
    +  private var checksums: Array[Int] = _
    +
       override protected def getValue() = {
         _value
       }
     
    +  private def caclChecksum(block: ByteBuffer): Int = {
    +    // block is HeapByteBuffer
    +    assert(block.hasArray)
    --- End diff --
    
    Hm..., it's surprising to me that this doesn't fail any test. It means we 
may have some unnecessary memory copy that converts DirectByteBuffer (from 
Netty) to HeapByteBuffer when fetching from remote block manager.
    
    Anyway, I think it's better to handle the non-array case like this:
    ```
    if (block.hasArray) {
       ...
    } else {
       byte[] bytes = new byte[block.remaining()]
       block.duplicate.get(bytes)
       adler.update(bytes)
    }
    
    ```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to