@@ -141,9 +141,9 @@ private FanOutOneBlockAsyncDFSOutputHelper() {
141
141
142
142
private interface LeaseManager {
143
143
144
- void begin (DFSClient client , HdfsFileStatus stat );
144
+ void begin (FanOutOneBlockAsyncDFSOutput output );
145
145
146
- void end (DFSClient client , HdfsFileStatus stat );
146
+ void end (FanOutOneBlockAsyncDFSOutput output );
147
147
}
148
148
149
149
private static final LeaseManager LEASE_MANAGER ;
@@ -178,44 +178,28 @@ private static LeaseManager createLeaseManager3_4() throws NoSuchMethodException
178
178
beginFileLeaseMethod .setAccessible (true );
179
179
Method endFileLeaseMethod = DFSClient .class .getDeclaredMethod ("endFileLease" , String .class );
180
180
endFileLeaseMethod .setAccessible (true );
181
- Method getConfigurationMethod = DFSClient .class .getDeclaredMethod ("getConfiguration" );
182
- getConfigurationMethod .setAccessible (true );
183
- Method getNamespaceMehtod = HdfsFileStatus .class .getDeclaredMethod ("getNamespace" );
184
-
181
+ Method getUniqKeyMethod = DFSOutputStream .class .getMethod ("getUniqKey" );
185
182
return new LeaseManager () {
186
183
187
- private static final String DFS_OUTPUT_STREAM_UNIQ_DEFAULT_KEY =
188
- "dfs.client.output.stream.uniq.default.key" ;
189
- private static final String DFS_OUTPUT_STREAM_UNIQ_DEFAULT_KEY_DEFAULT = "DEFAULT" ;
190
-
191
- private String getUniqId (DFSClient client , HdfsFileStatus stat )
192
- throws IllegalAccessException , IllegalArgumentException , InvocationTargetException {
193
- // Copied from DFSClient in Hadoop 3.4.0
194
- long fileId = stat .getFileId ();
195
- String namespace = (String ) getNamespaceMehtod .invoke (stat );
196
- if (namespace == null ) {
197
- Configuration conf = (Configuration ) getConfigurationMethod .invoke (client );
198
- String defaultKey = conf .get (DFS_OUTPUT_STREAM_UNIQ_DEFAULT_KEY ,
199
- DFS_OUTPUT_STREAM_UNIQ_DEFAULT_KEY_DEFAULT );
200
- return defaultKey + "_" + fileId ;
201
- } else {
202
- return namespace + "_" + fileId ;
203
- }
184
+ private String getUniqKey (FanOutOneBlockAsyncDFSOutput output )
185
+ throws IllegalAccessException , InvocationTargetException {
186
+ return (String ) getUniqKeyMethod .invoke (output .getDummyStream ());
204
187
}
205
188
206
189
@ Override
207
- public void begin (DFSClient client , HdfsFileStatus stat ) {
190
+ public void begin (FanOutOneBlockAsyncDFSOutput output ) {
208
191
try {
209
- beginFileLeaseMethod .invoke (client , getUniqId (client , stat ), null );
192
+ beginFileLeaseMethod .invoke (output .getClient (), getUniqKey (output ),
193
+ output .getDummyStream ());
210
194
} catch (IllegalAccessException | InvocationTargetException e ) {
211
195
throw new RuntimeException (e );
212
196
}
213
197
}
214
198
215
199
@ Override
216
- public void end (DFSClient client , HdfsFileStatus stat ) {
200
+ public void end (FanOutOneBlockAsyncDFSOutput output ) {
217
201
try {
218
- endFileLeaseMethod .invoke (client , getUniqId ( client , stat ));
202
+ endFileLeaseMethod .invoke (output . getClient (), getUniqKey ( output ));
219
203
} catch (IllegalAccessException | InvocationTargetException e ) {
220
204
throw new RuntimeException (e );
221
205
}
@@ -232,18 +216,19 @@ private static LeaseManager createLeaseManager3() throws NoSuchMethodException {
232
216
return new LeaseManager () {
233
217
234
218
@ Override
235
- public void begin (DFSClient client , HdfsFileStatus stat ) {
219
+ public void begin (FanOutOneBlockAsyncDFSOutput output ) {
236
220
try {
237
- beginFileLeaseMethod .invoke (client , stat .getFileId (), null );
221
+ beginFileLeaseMethod .invoke (output .getClient (), output .getDummyStream ().getFileId (),
222
+ output .getDummyStream ());
238
223
} catch (IllegalAccessException | InvocationTargetException e ) {
239
224
throw new RuntimeException (e );
240
225
}
241
226
}
242
227
243
228
@ Override
244
- public void end (DFSClient client , HdfsFileStatus stat ) {
229
+ public void end (FanOutOneBlockAsyncDFSOutput output ) {
245
230
try {
246
- endFileLeaseMethod .invoke (client , stat .getFileId ());
231
+ endFileLeaseMethod .invoke (output . getClient (), output . getDummyStream () .getFileId ());
247
232
} catch (IllegalAccessException | InvocationTargetException e ) {
248
233
throw new RuntimeException (e );
249
234
}
@@ -323,12 +308,12 @@ public boolean progress() {
323
308
}
324
309
}
325
310
326
- static void beginFileLease (DFSClient client , HdfsFileStatus stat ) {
327
- LEASE_MANAGER .begin (client , stat );
311
+ private static void beginFileLease (FanOutOneBlockAsyncDFSOutput output ) {
312
+ LEASE_MANAGER .begin (output );
328
313
}
329
314
330
- static void endFileLease (DFSClient client , HdfsFileStatus stat ) {
331
- LEASE_MANAGER .end (client , stat );
315
+ static void endFileLease (FanOutOneBlockAsyncDFSOutput output ) {
316
+ LEASE_MANAGER .end (output );
332
317
}
333
318
334
319
static DataChecksum createChecksum (DFSClient client ) {
@@ -540,20 +525,19 @@ private static FanOutOneBlockAsyncDFSOutput createOutput(DistributedFileSystem d
540
525
LOG .debug ("When create output stream for {}, exclude list is {}, retry={}" , src ,
541
526
getDataNodeInfo (toExcludeNodes ), retry );
542
527
}
528
+ EnumSetWritable <CreateFlag > createFlags = getCreateFlags (overwrite , noLocalWrite );
543
529
HdfsFileStatus stat ;
544
530
try {
545
531
stat = FILE_CREATOR .create (namenode , src ,
546
532
FsPermission .getFileDefault ().applyUMask (FsPermission .getUMask (conf )), clientName ,
547
- getCreateFlags (overwrite , noLocalWrite ), createParent , replication , blockSize ,
548
- CryptoProtocolVersion .supported ());
533
+ createFlags , createParent , replication , blockSize , CryptoProtocolVersion .supported ());
549
534
} catch (Exception e ) {
550
535
if (e instanceof RemoteException ) {
551
536
throw (RemoteException ) e ;
552
537
} else {
553
538
throw new NameNodeException (e );
554
539
}
555
540
}
556
- beginFileLease (client , stat );
557
541
boolean succ = false ;
558
542
LocatedBlock locatedBlock = null ;
559
543
List <Future <Channel >> futureList = null ;
@@ -578,7 +562,8 @@ private static FanOutOneBlockAsyncDFSOutput createOutput(DistributedFileSystem d
578
562
Encryptor encryptor = createEncryptor (conf , stat , client );
579
563
FanOutOneBlockAsyncDFSOutput output =
580
564
new FanOutOneBlockAsyncDFSOutput (conf , dfs , client , namenode , clientName , src , stat ,
581
- locatedBlock , encryptor , datanodes , summer , ALLOC , monitor );
565
+ createFlags .get (), locatedBlock , encryptor , datanodes , summer , ALLOC , monitor );
566
+ beginFileLease (output );
582
567
succ = true ;
583
568
return output ;
584
569
} catch (RemoteException e ) {
@@ -617,7 +602,6 @@ public void operationComplete(Future<Channel> future) throws Exception {
617
602
});
618
603
}
619
604
}
620
- endFileLease (client , stat );
621
605
}
622
606
}
623
607
}
@@ -654,12 +638,13 @@ public static boolean shouldRetryCreate(RemoteException e) {
654
638
return e .getClassName ().endsWith ("RetryStartFileException" );
655
639
}
656
640
657
- static void completeFile (DFSClient client , ClientProtocol namenode , String src , String clientName ,
658
- ExtendedBlock block , HdfsFileStatus stat ) {
641
+ static void completeFile (FanOutOneBlockAsyncDFSOutput output , DFSClient client ,
642
+ ClientProtocol namenode , String src , String clientName , ExtendedBlock block ,
643
+ HdfsFileStatus stat ) {
659
644
for (int retry = 0 ;; retry ++) {
660
645
try {
661
646
if (namenode .complete (src , clientName , block , stat .getFileId ())) {
662
- endFileLease (client , stat );
647
+ endFileLease (output );
663
648
return ;
664
649
} else {
665
650
LOG .warn ("complete file " + src + " not finished, retry = " + retry );
0 commit comments