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

    https://github.com/apache/spark/pull/18855#discussion_r131543602
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/DiskStore.scala ---
    @@ -165,6 +147,62 @@ private[spark] class DiskStore(
     
     }
     
    +private class DiskBlockData(
    +    conf: SparkConf,
    +    file: File,
    +    blockSize: Long) extends BlockData {
    +
    +  private val minMemoryMapBytes = 
conf.getSizeAsBytes("spark.storage.memoryMapThreshold", "2m")
    +
    +  override def toInputStream(): InputStream = new FileInputStream(file)
    +
    +  /**
    +  * Returns a Netty-friendly wrapper for the block's data.
    +  *
    +  * Please see `ManagedBuffer.convertToNetty()` for more details.
    +  */
    +  override def toNetty(): AnyRef = new DefaultFileRegion(file, 0, size)
    +
    +  override def toChunkedByteBuffer(allocator: (Int) => ByteBuffer): 
ChunkedByteBuffer = {
    +    Utils.tryWithResource(open()) { channel =>
    +      var remaining = blockSize
    +      val chunks = new ListBuffer[ByteBuffer]()
    +      while (remaining > 0) {
    +        val chunkSize = math.min(remaining, Int.MaxValue)
    +        val chunk = allocator(chunkSize.toInt)
    +        remaining -= chunkSize
    +        JavaUtils.readFully(channel, chunk)
    +        chunk.flip()
    +        chunks += chunk
    +      }
    +      new ChunkedByteBuffer(chunks.toArray)
    +    }
    +  }
    +
    +  override def toByteBuffer(): ByteBuffer = {
    +    require( size < Int.MaxValue
    +      , s"can't create a byte buffer of size $blockSize"
    +        + s" since it exceeds Int.MaxValue ${Int.MaxValue}.")
    +    Utils.tryWithResource(open()) { channel =>
    +      if (blockSize < minMemoryMapBytes) {
    +        // For small files, directly read rather than memory map.
    +        val buf = ByteBuffer.allocate(blockSize.toInt)
    +        JavaUtils.readFully(channel, buf)
    +        buf.flip()
    +        buf
    +      } else {
    +        channel.map(MapMode.READ_ONLY, 0, file.length)
    +      }
    +    }
    +  }
    +
    +  override def size: Long = blockSize
    +
    +  override def dispose(): Unit = {}
    +
    +    private def open() = new FileInputStream(file).getChannel
    --- End diff --
    
    will do :sunglasses: 


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