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

    https://github.com/apache/spark/pull/17295#discussion_r106962403
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/DiskStore.scala ---
    @@ -17,48 +17,61 @@
     
     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 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.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")
     
       def getSize(blockId: BlockId): Long = {
    -    diskManager.getFile(blockId.name).length
    +    val file = diskManager.getMetadataFile(blockId)
    +    Files.toString(file, UTF_8).toLong
       }
     
       /**
        * 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)
    +      Files.write(out.getCount().toString(), 
diskManager.getMetadataFile(blockId), UTF_8)
           threwException = false
         } finally {
           try {
    -        Closeables.close(fileOutputStream, threwException)
    +        Closeables.close(out, threwException)
    --- End diff --
    
    This was the previous behavior, but well, doesn't hurt to fix it.


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