Github user li-zhihui commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1616#discussion_r15447773
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -317,6 +317,28 @@ private[spark] object Utils extends Logging {
       }
     
       /**
    +   * Copy cached file to targetDir, if not exists, download it from url.
    +   */
    +  def fetchCachedFile(url: String, targetDir: File, conf: SparkConf, 
securityMgr: SecurityManager,
    +    timestamp: Long) {
    +    val fileName = url.split("/").last
    +    val cachedFileName = fileName + timestamp
    +    val targetFile = new File(targetDir, fileName)
    +    val lockFileName = fileName + timestamp + "_lock"
    +    val localDir = new File(getLocalDir(conf))
    +    val lockFile = new File(localDir, lockFileName)
    +    val raf = new RandomAccessFile(lockFile, "rw")
    +    val lock = raf.getChannel().lock() // only one executor entry
    +    val cachedFile = new File(localDir, cachedFileName)
    +    if (!cachedFile.exists()) {
    +      fetchFile(url, localDir, conf, securityMgr)
    +      Files.move(new File(localDir, fileName), cachedFile)
    +    }
    +    lock.release()
    --- End diff --
    
    thanks @harishreedharan done.


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

Reply via email to