瀏覽代碼

commit b6f3b4b2fceabed7243a282592941692a5731b65
Author: Konstantin Shvachko <shv@cdev6023.inktomisearch.com>
Date: Fri Aug 6 21:34:56 2010 +0000

HDFS-495 from https://issues.apache.org/jira/secure/attachment/12451466/HDFS-495.patch

+++ b/YAHOO-CHANGES.txt
+ HDFS-495. New clients should be able to take over files lease if the old
+ client died. (shv)
+


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077648 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 年之前
父節點
當前提交
a7fd8cfb16

+ 15 - 15
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1141,28 +1141,28 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean,
         // If the file is under construction , then it must be in our
         // If the file is under construction , then it must be in our
         // leases. Find the appropriate lease record.
         // leases. Find the appropriate lease record.
         //
         //
-        Lease lease = leaseManager.getLease(holder);
-        //
-        // We found the lease for this file. And surprisingly the original
-        // holder is trying to recreate this file. This should never occur.
-        //
-        if (lease != null) {
+        Lease lease = leaseManager.getLeaseByPath(src);
+        if (lease == null) {
           throw new AlreadyBeingCreatedException(
           throw new AlreadyBeingCreatedException(
-                                                 "failed to create file " + src + " for " + holder +
-                                                 " on client " + clientMachine + 
-                                                 " because current leaseholder is trying to recreate file.");
+              "failed to create file " + src + " for " + holder +
+              " on client " + clientMachine + 
+              " because pendingCreates is non-null but no leases found.");
         }
         }
         //
         //
-        // Find the original holder.
+        // We found the lease for this file. And surprisingly the original
+        // holder is trying to recreate this file. This should never occur.
         //
         //
-        lease = leaseManager.getLease(pendingFile.clientName);
-        if (lease == null) {
+        if (lease.getHolder().equals(holder)) {
           throw new AlreadyBeingCreatedException(
           throw new AlreadyBeingCreatedException(
-                                                 "failed to create file " + src + " for " + holder +
-                                                 " on client " + clientMachine + 
-                                                 " because pendingCreates is non-null but no leases found.");
+              "failed to create file " + src + " for " + holder +
+              " on client " + clientMachine + 
+              " because current leaseholder is trying to recreate file.");
         }
         }
+        assert lease.getHolder().equals(pendingFile.getClientName()) :
+            "Current lease holder " + lease.getHolder() +
+            " does not match file creator " + pendingFile.getClientName();
         //
         //
+        // Current lease holder is different from the requester.
         // If the original holder has not renewed in the last SOFTLIMIT 
         // If the original holder has not renewed in the last SOFTLIMIT 
         // period, then start lease recovery.
         // period, then start lease recovery.
         //
         //

+ 5 - 1
src/hdfs/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java

@@ -265,7 +265,11 @@ public class LeaseManager {
     Collection<String> getPaths() {
     Collection<String> getPaths() {
       return paths;
       return paths;
     }
     }
-    
+
+    String getHolder() {
+    	return holder;
+    }
+
     void replacePath(String oldpath, String newpath) {
     void replacePath(String oldpath, String newpath) {
       paths.remove(oldpath);
       paths.remove(oldpath);
       paths.add(newpath);
       paths.add(newpath);