From 6151c2bea7bcd9e458b09a5bf5b1798ed6c0def9 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Thu, 11 Sep 2014 10:59:09 -0700 Subject: [PATCH] HDFS-7045. Fix NameNode deadlock when opening file under /.reserved path. Contributed by Yi Liu. (cherry picked from commit 1e684995d7ac20d1c27ca1c1bef37dd2ee00e630) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/FSNamesystem.java | 2 +- .../java/org/apache/hadoop/hdfs/TestRead.java | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 3b3a723e01d..6c8282c5926 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index fa77526a50b..5b0c3f761cb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/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 { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRead.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRead.java index c8d50297b3d..378d8bba153 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRead.java +++ b/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(); + } + } }