瀏覽代碼

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-0.22@1239878 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon 13 年之前
父節點
當前提交
c0d7cc0213
共有 2 個文件被更改,包括 14 次插入1 次删除
  1. 3 0
      hdfs/CHANGES.txt
  2. 11 1
      hdfs/src/java/org/apache/hadoop/hdfs/server/common/Storage.java

+ 3 - 0
hdfs/CHANGES.txt

@@ -19,6 +19,9 @@ Release 0.22.1 - Unreleased
     HDFS-2698. BackupNode is downloading image from NameNode for every 
     checkpoint. (shv)
 
+    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

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

@@ -626,8 +626,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 {
@@ -640,6 +644,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;
     }