Explorar o código

HDFS-7045. Fix NameNode deadlock when opening file under /.reserved path. Contributed by Yi Liu.

(cherry picked from commit 1e684995d7ac20d1c27ca1c1bef37dd2ee00e630)
Andrew Wang %!s(int64=10) %!d(string=hai) anos
pai
achega
6151c2bea7

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -383,6 +383,9 @@ Release 2.6.0 - UNRELEASED
     HDFS-6621. Hadoop Balancer prematurely exits iterations.
     (Rafal Wojdyla and Benjamin Bowman via wang)
 
+    HDFS-7045. Fix NameNode deadlock when opening file under /.reserved path.
+    (Yi Liu via wang)
+
     BREAKDOWN OF HDFS-6134 AND HADOOP-10150 SUBTASKS AND RELATED JIRAS
   
       HDFS-6387. HDFS CLI admin tool for creating & deleting an

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1824,8 +1824,8 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
         checkOperation(OperationCategory.WRITE);
         writeLock(); // writelock is needed to set accesstime
       }
-      src = resolvePath(src, pathComponents);
       try {
+        src = resolvePath(src, pathComponents);
         if (isReadOp) {
           checkOperation(OperationCategory.READ);
         } else {

+ 22 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRead.java

@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.hdfs;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
@@ -80,4 +81,25 @@ public class TestRead {
     testEOF(cluster, 10000);   
     cluster.shutdown();
   }
+
+  /**
+   * Regression test for HDFS-7045.
+   * If deadlock happen, the test will time out.
+   * @throws Exception
+   */
+  @Test(timeout=60000)
+  public void testReadReservedPath() throws Exception {
+    Configuration conf = new Configuration();
+    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).
+        numDataNodes(1).format(true).build();
+    try {
+      FileSystem fs = cluster.getFileSystem();
+      fs.open(new Path("/.reserved/.inodes/file"));
+      Assert.fail("Open a non existing file should fail.");
+    } catch (FileNotFoundException e) {
+      // Expected
+    } finally {
+      cluster.shutdown();
+    }
+  }
 }