Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-4323] Utils#fetchFile method should close lock file certainly #3186

Closed
wants to merge 1 commit into from

Conversation

sarutak
Copy link
Member

@sarutak sarutak commented Nov 10, 2014

In Utils#fetchFile method, lock file is created like as follows.

    val raf = new RandomAccessFile(lockFile, "rw")                                                                                                          
    // Only one executor entry.                                                                                                                             
    // The FileLock is only used to control synchronization for executors download file,                                                                    
    // it's always safe regardless of lock type (mandatory or advisory).                                                                                    
    val lock = raf.getChannel().lock()                                                                                                                      
    val cachedFile = new File(localDir, cachedFileName)                                                                                                     
    try {                                                                                                                                                   
      if (!cachedFile.exists()) {                                                                                                                           
        doFetchFile(url, localDir, cachedFileName, conf, securityMgr, hadoopConf)                                                                           
      }                                                                                                                                                     
    } finally {                                                                                                                                             
      lock.release()                                                                                                                                        
    }  

If some error occurs between opening RandomAccessFile and getting lock, lock file can be not closed.

// The FileLock is only used to control synchronization for executors download file,
// it's always safe regardless of lock type (mandatory or advisory).
val lock = raf.getChannel().lock()
val cachedFile = new File(localDir, cachedFileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only statement after the lock acquisition. It doesn't throw anything (unless you want to be pedantic and say it can throw an OutOfMemoryError), so it shouldn't cause problems. But if you want to be pedantic, you could achieve the exact same behavior by moving this statement one line up (before the lock acquisition). Which is much simpler than your patch.

@SparkQA
Copy link

SparkQA commented Nov 10, 2014

Test build #23155 has started for PR 3186 at commit a2b30bc.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Nov 10, 2014

Test build #23155 has finished for PR 3186 at commit a2b30bc.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/23155/
Test PASSed.

@pwendell
Copy link
Contributor

The construction of a File cannot cause an exception, so I think the existing code is safe, right?

@sarutak
Copy link
Member Author

sarutak commented Nov 11, 2014

As @vanzin said, I considered some corner cases like OOM. If we don't need to worry about that, I'll close this PR.

@sarutak sarutak closed this Dec 11, 2014
@sarutak sarutak deleted the SPARK-4323 branch April 11, 2015 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants