3434
3535import static org .apache .hadoop .util .Time .now ;
3636
37+ /**
38+ * Restrictions for a concat operation:
39+ * <pre>
40+ * 1. the src file and the target file are in the same dir
41+ * 2. all the source files are not in snapshot
42+ * 3. any source file cannot be the same with the target file
43+ * 4. source files cannot be under construction or empty
44+ * 5. source file's preferred block size cannot be greater than the target file
45+ * </pre>
46+ */
3747class FSDirConcatOp {
3848
3949 static HdfsFileStatus concat (FSDirectory fsd , String target , String [] srcs ,
@@ -123,14 +133,25 @@ private static INodeFile[] verifySrcFiles(FSDirectory fsd, String[] srcs,
123133 throw new SnapshotException ("Concat: the source file " + src
124134 + " is referred by some other reference in some snapshot." );
125135 }
136+ // source file cannot be the same with the target file
126137 if (srcINode == targetINode ) {
127138 throw new HadoopIllegalArgumentException ("concat: the src file " + src
128139 + " is the same with the target file " + targetIIP .getPath ());
129140 }
141+ // source file cannot be under construction or empty
130142 if (srcINodeFile .isUnderConstruction () || srcINodeFile .numBlocks () == 0 ) {
131143 throw new HadoopIllegalArgumentException ("concat: source file " + src
132144 + " is invalid or empty or underConstruction" );
133145 }
146+ // source file's preferred block size cannot be greater than the target
147+ // file
148+ if (srcINodeFile .getPreferredBlockSize () >
149+ targetINode .getPreferredBlockSize ()) {
150+ throw new HadoopIllegalArgumentException ("concat: source file " + src
151+ + " has preferred block size " + srcINodeFile .getPreferredBlockSize ()
152+ + " which is greater than the target file's preferred block size "
153+ + targetINode .getPreferredBlockSize ());
154+ }
134155 si .add (srcINodeFile );
135156 }
136157
@@ -143,9 +164,10 @@ private static INodeFile[] verifySrcFiles(FSDirectory fsd, String[] srcs,
143164 return si .toArray (new INodeFile [si .size ()]);
144165 }
145166
146- private static QuotaCounts computeQuotaDeltas (FSDirectory fsd , INodeFile target , INodeFile [] srcList ) {
167+ private static QuotaCounts computeQuotaDeltas (FSDirectory fsd ,
168+ INodeFile target , INodeFile [] srcList ) {
147169 QuotaCounts deltas = new QuotaCounts .Builder ().build ();
148- short targetRepl = target .getBlockReplication ();
170+ final short targetRepl = target .getBlockReplication ();
149171 for (INodeFile src : srcList ) {
150172 short srcRepl = src .getBlockReplication ();
151173 long fileSize = src .computeFileSize ();
0 commit comments