34
34
35
35
import static org .apache .hadoop .util .Time .now ;
36
36
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
+ */
37
47
class FSDirConcatOp {
38
48
39
49
static HdfsFileStatus concat (FSDirectory fsd , String target , String [] srcs ,
@@ -123,14 +133,25 @@ private static INodeFile[] verifySrcFiles(FSDirectory fsd, String[] srcs,
123
133
throw new SnapshotException ("Concat: the source file " + src
124
134
+ " is referred by some other reference in some snapshot." );
125
135
}
136
+ // source file cannot be the same with the target file
126
137
if (srcINode == targetINode ) {
127
138
throw new HadoopIllegalArgumentException ("concat: the src file " + src
128
139
+ " is the same with the target file " + targetIIP .getPath ());
129
140
}
141
+ // source file cannot be under construction or empty
130
142
if (srcINodeFile .isUnderConstruction () || srcINodeFile .numBlocks () == 0 ) {
131
143
throw new HadoopIllegalArgumentException ("concat: source file " + src
132
144
+ " is invalid or empty or underConstruction" );
133
145
}
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
+ }
134
155
si .add (srcINodeFile );
135
156
}
136
157
@@ -143,9 +164,10 @@ private static INodeFile[] verifySrcFiles(FSDirectory fsd, String[] srcs,
143
164
return si .toArray (new INodeFile [si .size ()]);
144
165
}
145
166
146
- private static QuotaCounts computeQuotaDeltas (FSDirectory fsd , INodeFile target , INodeFile [] srcList ) {
167
+ private static QuotaCounts computeQuotaDeltas (FSDirectory fsd ,
168
+ INodeFile target , INodeFile [] srcList ) {
147
169
QuotaCounts deltas = new QuotaCounts .Builder ().build ();
148
- short targetRepl = target .getBlockReplication ();
170
+ final short targetRepl = target .getBlockReplication ();
149
171
for (INodeFile src : srcList ) {
150
172
short srcRepl = src .getBlockReplication ();
151
173
long fileSize = src .computeFileSize ();
0 commit comments