Skip to content

Commit ee7c746

Browse files
aajisakajojochuang
authored andcommitted
HDFS-15286. Concat on a same file deleting the file. Contributed by hemanthboyina.
(cherry picked from commit 5e0eda5) (cherry picked from commit d504574) Change-Id: I742848d02710aff1c5ca57ef9c4df80bd679f039
1 parent 21dfdfc commit ee7c746

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static INodeFile[] verifySrcFiles(FSDirectory fsd, String[] srcs,
150150
+ " is referred by some other reference in some snapshot.");
151151
}
152152
// source file cannot be the same with the target file
153-
if (srcINode == targetINode) {
153+
if (srcINode.equals(targetINode)) {
154154
throw new HadoopIllegalArgumentException("concat: the src file " + src
155155
+ " is the same with the target file " + targetIIP.getPath());
156156
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.hadoop.ipc.RemoteException;
4646
import org.apache.hadoop.security.UserGroupInformation;
4747
import org.apache.hadoop.test.GenericTestUtils;
48+
import org.apache.hadoop.test.LambdaTestUtils;
4849
import org.junit.After;
4950
import org.junit.Assert;
5051
import org.junit.Before;
@@ -525,4 +526,42 @@ public void testConcatReservedRelativePaths() throws IOException {
525526
GenericTestUtils.assertExceptionContains(errMsg, e);
526527
}
527528
}
529+
530+
/**
531+
* Test concat on same source and target file which is a inode reference.
532+
*/
533+
@Test
534+
public void testConcatOnSameFile() throws Exception {
535+
String dir = "/dir1";
536+
Path trgDir = new Path(dir);
537+
dfs.mkdirs(new Path(dir));
538+
539+
// create a source file
540+
String dir2 = "/dir2";
541+
Path srcDir = new Path(dir2);
542+
dfs.mkdirs(srcDir);
543+
dfs.allowSnapshot(srcDir);
544+
Path src = new Path(srcDir, "file1");
545+
DFSTestUtil.createFile(dfs, src, 512, (short) 2, 0);
546+
547+
// make the file as an Inode reference and delete the reference
548+
dfs.createSnapshot(srcDir, "s1");
549+
dfs.rename(src, trgDir);
550+
dfs.deleteSnapshot(srcDir, "s1");
551+
Path[] srcs = new Path[1];
552+
srcs[0] = new Path(dir, "file1");
553+
554+
// perform concat
555+
LambdaTestUtils.intercept(RemoteException.class,
556+
"concat: the src file /dir1/file1 is the same with the target"
557+
+ " file /dir1/file1",
558+
() -> dfs.concat(srcs[0], srcs));
559+
560+
// the file should exists and read the file
561+
byte[] buff = new byte[1080];
562+
FSDataInputStream stream = dfs.open(srcs[0]);
563+
stream.readFully(0, buff, 0, 512);
564+
565+
assertEquals(1, dfs.getContentSummary(new Path(dir)).getFileCount());
566+
}
528567
}

0 commit comments

Comments
 (0)