Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17295#discussion_r107327188
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/DiskStore.scala ---
    @@ -17,48 +17,67 @@
     
     package org.apache.spark.storage
     
    -import java.io.{FileOutputStream, IOException, RandomAccessFile}
    +import java.io._
     import java.nio.ByteBuffer
    +import java.nio.channels.{Channels, ReadableByteChannel, 
WritableByteChannel}
     import java.nio.channels.FileChannel.MapMode
    +import java.nio.charset.StandardCharsets.UTF_8
    +import java.util.concurrent.ConcurrentHashMap
     
    -import com.google.common.io.Closeables
    +import scala.collection.mutable.ListBuffer
     
    -import org.apache.spark.SparkConf
    +import com.google.common.io.{ByteStreams, Closeables, Files}
    +import io.netty.channel.FileRegion
    +import io.netty.util.AbstractReferenceCounted
    +
    +import org.apache.spark.{SecurityManager, SparkConf}
     import org.apache.spark.internal.Logging
    -import org.apache.spark.util.Utils
    +import org.apache.spark.network.buffer.ManagedBuffer
    +import org.apache.spark.network.util.JavaUtils
    +import org.apache.spark.security.CryptoStreamUtils
    +import org.apache.spark.util.{ByteBufferInputStream, Utils}
     import org.apache.spark.util.io.ChunkedByteBuffer
     
     /**
      * Stores BlockManager blocks on disk.
      */
    -private[spark] class DiskStore(conf: SparkConf, diskManager: 
DiskBlockManager) extends Logging {
    +private[spark] class DiskStore(
    +    conf: SparkConf,
    +    diskManager: DiskBlockManager,
    +    securityManager: SecurityManager) extends Logging {
     
       private val minMemoryMapBytes = 
conf.getSizeAsBytes("spark.storage.memoryMapThreshold", "2m")
    +  private val blockSizes = new ConcurrentHashMap[String, Long]()
     
    -  def getSize(blockId: BlockId): Long = {
    -    diskManager.getFile(blockId.name).length
    -  }
    +  def getSize(blockId: BlockId): Long = blockSizes.get(blockId.name)
     
       /**
        * Invokes the provided callback function to write the specific block.
        *
        * @throws IllegalStateException if the block already exists in the disk 
store.
        */
    -  def put(blockId: BlockId)(writeFunc: FileOutputStream => Unit): Unit = {
    +  def put(blockId: BlockId)(writeFunc: WritableByteChannel => Unit): Unit 
= {
         if (contains(blockId)) {
           throw new IllegalStateException(s"Block $blockId is already present 
in the disk store")
         }
         logDebug(s"Attempting to put block $blockId")
         val startTime = System.currentTimeMillis
         val file = diskManager.getFile(blockId)
    -    val fileOutputStream = new FileOutputStream(file)
    +    val out = new CountingWritableChannel(openForWrite(file))
         var threwException: Boolean = true
         try {
    -      writeFunc(fileOutputStream)
    +      writeFunc(out)
    +      blockSizes.put(blockId.name, out.getCount)
           threwException = false
         } finally {
           try {
    -        Closeables.close(fileOutputStream, threwException)
    +        out.close()
    +      } catch {
    +        case ioe: IOException =>
    --- End diff --
    
    why this? `threwException` starts with `true`


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