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

    https://github.com/apache/spark/pull/2866#discussion_r19307726
  
    --- Diff: core/src/main/scala/org/apache/spark/scheduler/MapStatus.scala ---
    @@ -112,35 +119,82 @@ private[spark] class CompressedMapStatus(
       }
     }
     
    -
     /**
    - * A [[MapStatus]] implementation that only stores the average size of the 
blocks.
    + * A [[MapStatus]] implementation that only stores the average size of 
non-empty blocks,
    + * plus a bitmap for tracking which blocks are non-empty.
      *
    - * @param loc location where the task is being executed.
    - * @param avgSize average size of all the blocks
    + * @param loc location where the task is being executed
    + * @param numNonEmptyBlocks the number of non-empty blocks
    + * @param emptyBlocks a bitmap tracking which blocks are empty
    + * @param avgSize average size of the non-empty blocks
      */
    -private[spark] class HighlyCompressedMapStatus(
    +private[spark] class HighlyCompressedMapStatus private (
         private[this] var loc: BlockManagerId,
    +    private[this] var numNonEmptyBlocks: Int,
    +    private[this] var emptyBlocks: RoaringBitmap,
         private[this] var avgSize: Long)
       extends MapStatus with Externalizable {
     
    -  def this(loc: BlockManagerId, uncompressedSizes: Array[Long]) {
    -    this(loc, uncompressedSizes.sum / uncompressedSizes.length)
    -  }
    +  require(loc == null || avgSize > 0 || numNonEmptyBlocks == 0,
    +    "Average size can only be zero for map stages that produced no output")
     
    -  protected def this() = this(null, 0L)  // For deserialization only
    +  protected def this() = this(null, -1, null, -1)  // For deserialization 
only
     
       override def location: BlockManagerId = loc
     
    -  override def getSizeForBlock(reduceId: Int): Long = avgSize
    +  // This set allows for constant-time lookup of whether a block is empty
    +  private var emptyBlocksSet: Set[Int] = 
Option(emptyBlocks).map(_.toArray.toSet).orNull
    +
    +  override def getSizeForBlock(reduceId: Int): Long = {
    +    if (emptyBlocksSet.contains(reduceId)) {
    +      0
    +    } else {
    +      avgSize
    +    }
    +  }
     
       override def writeExternal(out: ObjectOutput): Unit = {
         loc.writeExternal(out)
    +    emptyBlocks.writeExternal(out)
         out.writeLong(avgSize)
       }
     
       override def readExternal(in: ObjectInput): Unit = {
         loc = BlockManagerId(in)
    +    emptyBlocks = new RoaringBitmap()
    +    emptyBlocks.readExternal(in)
    +    emptyBlocksSet = emptyBlocks.toArray.toSet
         avgSize = in.readLong()
       }
     }
    +
    +object HighlyCompressedMapStatus {
    +  def apply(loc: BlockManagerId, uncompressedSizes: Array[Long]): 
HighlyCompressedMapStatus = {
    +    // We must keep track of which blocks are empty so that we don't 
report a zero-sized
    +    // block as being non-empty (or vice-versa) when using the average 
block size.
    +    var i = 0
    +    var numNonEmptyBlocks: Int = 0
    +    var totalSize: Long = 0
    +    // From a compression standpoint, it shouldn't matter whether we track 
empty or non-empty
    +    // blocks.  From a performance standpoint, we benefit from tracking 
empty blocks because
    --- End diff --
    
    1 too many spaces here


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