HDFS-2877. If locking of a storage dir fails, it will remove the other NN's lock file on exit. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1239880 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2012-02-02 22:12:02 +00:00
parent 9eb8f4d267
commit 6d5510dfb8
2 changed files with 14 additions and 1 deletions

View File

@ -1672,6 +1672,9 @@ Release 0.22.1 - Unreleased
BUG FIXES
HDFS-2877. If locking of a storage dir fails, it will remove the other
NN's lock file on exit. (todd)
Release 0.22.0 - 2011-11-29
INCOMPATIBLE CHANGES

View File

@ -599,8 +599,12 @@ public abstract class Storage extends StorageInfo {
* @throws IOException if locking fails.
*/
FileLock tryLock() throws IOException {
boolean deletionHookAdded = false;
File lockF = new File(root, STORAGE_FILE_LOCK);
lockF.deleteOnExit();
if (!lockF.exists()) {
lockF.deleteOnExit();
deletionHookAdded = true;
}
RandomAccessFile file = new RandomAccessFile(lockF, "rws");
FileLock res = null;
try {
@ -613,6 +617,12 @@ public abstract class Storage extends StorageInfo {
file.close();
throw e;
}
if (res != null && !deletionHookAdded) {
// If the file existed prior to our startup, we didn't
// call deleteOnExit above. But since we successfully locked
// the dir, we can take care of cleaning it up.
lockF.deleteOnExit();
}
return res;
}