diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java index 3070957e3d..de710a1c87 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java @@ -544,7 +544,7 @@ public boolean removeChild(final INode child) { } final INode removed = children.remove(i); - Preconditions.checkState(removed == child); + Preconditions.checkState(removed.equals(child)); return true; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java index ed0f074286..5f789e81cb 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java @@ -1319,4 +1319,38 @@ public void testQuotaOnTruncateWithSnapshot() throws Exception { assertEquals(fs.getContentSummary(root).getSpaceConsumed(), fs.getQuotaUsage(root).getSpaceConsumed()); } + + /** + * Test concat on file which is a reference. + */ + @Test + public void testConcatOnInodeRefernce() throws IOException { + String dir = "/testConcat"; + Path trgDir = new Path(dir); + fs.mkdirs(new Path(dir), FsPermission.getDirDefault()); + + // Create a target file + Path trg = new Path(dir, "file"); + DFSTestUtil.createFile(fs, trg, 512, (short) 2, 0); + + String dir2 = "/dir2"; + Path srcDir = new Path(dir2); + // create a source file + fs.mkdirs(srcDir); + fs.allowSnapshot(srcDir); + Path src = new Path(srcDir, "file1"); + DFSTestUtil.createFile(fs, src, 512, (short) 2, 0); + + // make the file as an Inode reference and delete the reference + fs.createSnapshot(srcDir, "s1"); + fs.rename(src, trgDir); + fs.deleteSnapshot(srcDir, "s1"); + Path[] srcs = new Path[1]; + srcs[0] = new Path(dir, "file1"); + assertEquals(2, fs.getContentSummary(new Path(dir)).getFileCount()); + + // perform concat + fs.concat(trg, srcs); + assertEquals(1, fs.getContentSummary(new Path(dir)).getFileCount()); + } }