Pārlūkot izejas kodu

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/branches/branch-1@1239877 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon 13 gadi atpakaļ
vecāks
revīzija
535072abeb

+ 3 - 0
CHANGES.txt

@@ -89,6 +89,9 @@ Release 1.1.0 - unreleased
     HADOOP-7988. Upper case in hostname part of the principals doesn't work with 
     HADOOP-7988. Upper case in hostname part of the principals doesn't work with 
     kerberos. (jitendra)
     kerberos. (jitendra)
 
 
+    HDFS-2877. If locking of a storage dir fails, it will remove the other
+    NN's lock file on exit. (todd)
+
   IMPROVEMENTS
   IMPROVEMENTS
 
 
     MAPREDUCE-3597. [Rumen] Provide a way to access other info of history file
     MAPREDUCE-3597. [Rumen] Provide a way to access other info of history file

+ 11 - 1
src/hdfs/org/apache/hadoop/hdfs/server/common/Storage.java

@@ -611,8 +611,12 @@ public abstract class Storage extends StorageInfo {
      * @throws IOException if locking fails.
      * @throws IOException if locking fails.
      */
      */
     FileLock tryLock() throws IOException {
     FileLock tryLock() throws IOException {
+      boolean deletionHookAdded = false;
       File lockF = new File(root, STORAGE_FILE_LOCK);
       File lockF = new File(root, STORAGE_FILE_LOCK);
-      lockF.deleteOnExit();
+      if (!lockF.exists()) {
+        lockF.deleteOnExit();
+        deletionHookAdded = true;
+      }
       RandomAccessFile file = new RandomAccessFile(lockF, "rws");
       RandomAccessFile file = new RandomAccessFile(lockF, "rws");
       FileLock res = null;
       FileLock res = null;
       try {
       try {
@@ -625,6 +629,12 @@ public abstract class Storage extends StorageInfo {
         file.close();
         file.close();
         throw e;
         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;
       return res;
     }
     }