Skip to content

Commit 5958af4

Browse files
committed
HDFS-15276. Concat on INodeRefernce fails with illegal state exception. Contributed by hemanthboyina
1 parent af85971 commit 5958af4

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ public boolean removeChild(final INode child) {
544544
}
545545

546546
final INode removed = children.remove(i);
547-
Preconditions.checkState(removed == child);
547+
Preconditions.checkState(removed.equals(child));
548548
return true;
549549
}
550550

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,4 +1319,38 @@ public void testQuotaOnTruncateWithSnapshot() throws Exception {
13191319
assertEquals(fs.getContentSummary(root).getSpaceConsumed(),
13201320
fs.getQuotaUsage(root).getSpaceConsumed());
13211321
}
1322+
1323+
/**
1324+
* Test concat on file which is a reference.
1325+
*/
1326+
@Test
1327+
public void testConcatOnInodeRefernce() throws IOException {
1328+
String dir = "/testConcat";
1329+
Path trgDir = new Path(dir);
1330+
fs.mkdirs(new Path(dir), FsPermission.getDirDefault());
1331+
1332+
// Create a target file
1333+
Path trg = new Path(dir, "file");
1334+
DFSTestUtil.createFile(fs, trg, 512, (short) 2, 0);
1335+
1336+
String dir2 = "/dir2";
1337+
Path srcDir = new Path(dir2);
1338+
// create a source file
1339+
fs.mkdirs(srcDir);
1340+
fs.allowSnapshot(srcDir);
1341+
Path src = new Path(srcDir, "file1");
1342+
DFSTestUtil.createFile(fs, src, 512, (short) 2, 0);
1343+
1344+
// make the file as an Inode reference and delete the reference
1345+
fs.createSnapshot(srcDir, "s1");
1346+
fs.rename(src, trgDir);
1347+
fs.deleteSnapshot(srcDir, "s1");
1348+
Path[] srcs = new Path[1];
1349+
srcs[0] = new Path(dir, "file1");
1350+
assertEquals(2, fs.getContentSummary(new Path(dir)).getFileCount());
1351+
1352+
// perform concat
1353+
fs.concat(trg, srcs);
1354+
assertEquals(1, fs.getContentSummary(new Path(dir)).getFileCount());
1355+
}
13221356
}

0 commit comments

Comments
 (0)