diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6ef6329e30..12cac83d75 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java index 4c11973d4a..3de906701f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java @@ -599,8 +599,12 @@ public void lock() throws IOException { * @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 @@ FileLock tryLock() throws IOException { 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; }