spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viirya <...@git.apache.org>
Subject [GitHub] spark pull request #10225: [SPARK-12196][Core] Store/retrieve blocks from di...
Date Mon, 05 Sep 2016 07:28:05 GMT
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10225#discussion_r77479267
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/DiskBlockManager.scala ---
    @@ -50,33 +50,98 @@ private[spark] class DiskBlockManager(conf: SparkConf, deleteFilesOnStop:
Boolea
     
       private val shutdownHook = addShutdownHook()
     
    +  private abstract class FileAllocationStrategy {
    +    def apply(filename: String): File
    +
    +    protected def getFile(filename: String, storageDirs: Array[File]): File = {
    +      require(storageDirs.nonEmpty, "could not find file when the directories are empty")
    +
    +      // Figure out which local directory it hashes to, and which subdirectory in that
    +      val hash = Utils.nonNegativeHash(filename)
    +      val dirId = localDirs.indexOf(storageDirs(hash % storageDirs.length))
    +      val subDirId = (hash / storageDirs.length) % subDirsPerLocalDir
    +
    +      // Create the subdirectory if it doesn't already exist
    +      val subDir = subDirs(dirId).synchronized {
    +        val old = subDirs(dirId)(subDirId)
    +        if (old != null) {
    +          old
    +        } else {
    +          val newDir = new File(localDirs(dirId), "%02x".format(subDirId))
    +          if (!newDir.exists() && !newDir.mkdir()) {
    +            throw new IOException(s"Failed to create local dir in $newDir.")
    +          }
    +          subDirs(dirId)(subDirId) = newDir
    +          newDir
    +        }
    +      }
    +
    +      new File(subDir, filename)
    +    }
    +  }
    +
       /** Looks up a file by hashing it into one of our local subdirectories. */
       // This method should be kept in sync with
       // org.apache.spark.network.shuffle.ExternalShuffleBlockResolver#getFile().
    -  def getFile(filename: String): File = {
    -    // Figure out which local directory it hashes to, and which subdirectory in that
    -    val hash = Utils.nonNegativeHash(filename)
    -    val dirId = hash % localDirs.length
    -    val subDirId = (hash / localDirs.length) % subDirsPerLocalDir
    -
    -    // Create the subdirectory if it doesn't already exist
    -    val subDir = subDirs(dirId).synchronized {
    -      val old = subDirs(dirId)(subDirId)
    -      if (old != null) {
    -        old
    -      } else {
    -        val newDir = new File(localDirs(dirId), "%02x".format(subDirId))
    -        if (!newDir.exists() && !newDir.mkdir()) {
    -          throw new IOException(s"Failed to create local dir in $newDir.")
    -        }
    -        subDirs(dirId)(subDirId) = newDir
    -        newDir
    +  private object hashAllocator extends FileAllocationStrategy {
    +    def apply(filename: String): File = getFile(filename, localDirs)
    +  }
    +
    +  /** Looks up a file by hierarchy way in different speed storage devices. */
    +  private val hierarchy = conf.getOption("spark.diskStore.hierarchy")
    +  private class HierarchyAllocator extends FileAllocationStrategy {
    +    case class Level(key: String, threshold: Long, dirs: Array[File])
    +    val hsDescs: Array[(String, Long)] =
    +      // e.g.: hierarchy = "ram_disk 1GB, ssd 20GB"
    +      hierarchy.get.trim.split(",").map {
    +        s => val x = s.trim.split(" +")
    +          val storage = x(0).toLowerCase
    +          val threshold = s.replaceFirst(x(0), "").trim
    +          (storage, Utils.byteStringAsBytes(threshold))
    --- End diff --
    
    style:
    
        hierarchy.get.trim.split(",").map { s =>
          val x = s.trim.split(" +")
          val storage = x(0).toLowerCase
        


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

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


Mime
View raw message