21
21
import java .io .IOException ;
22
22
import java .nio .charset .StandardCharsets ;
23
23
import java .nio .ByteBuffer ;
24
- import java .nio .file .Files ;
25
24
import java .util .List ;
26
25
import java .util .Map ;
27
26
@@ -340,17 +339,17 @@ protected Path getRecoveryPath(String fileName) {
340
339
* when it previously was not. If YARN NM recovery is enabled it uses that path, otherwise
341
340
* it will uses a YARN local dir.
342
341
*/
343
- protected File initRecoveryDb (String dbFileName ) {
342
+ protected File initRecoveryDb (String dbName ) {
344
343
if (_recoveryPath != null ) {
345
- File recoveryFile = new File (_recoveryPath .toUri ().getPath (), dbFileName );
344
+ File recoveryFile = new File (_recoveryPath .toUri ().getPath (), dbName );
346
345
if (recoveryFile .exists ()) {
347
346
return recoveryFile ;
348
347
}
349
348
}
350
349
// db doesn't exist in recovery path go check local dirs for it
351
350
String [] localDirs = _conf .getTrimmedStrings ("yarn.nodemanager.local-dirs" );
352
351
for (String dir : localDirs ) {
353
- File f = new File (new Path (dir ).toUri ().getPath (), dbFileName );
352
+ File f = new File (new Path (dir ).toUri ().getPath (), dbName );
354
353
if (f .exists ()) {
355
354
if (_recoveryPath == null ) {
356
355
// If NM recovery is not enabled, we should specify the recovery path using NM local
@@ -363,25 +362,29 @@ protected File initRecoveryDb(String dbFileName) {
363
362
// make sure to move all DBs to the recovery path from the old NM local dirs.
364
363
// If another DB was initialized first just make sure all the DBs are in the same
365
364
// location.
366
- File newLoc = new File (_recoveryPath .toUri ().getPath (), dbFileName );
367
- if (!newLoc .equals (f )) {
365
+ Path newLoc = new Path (_recoveryPath , dbName );
366
+ Path copyFrom = new Path (f .toURI ());
367
+ if (!newLoc .equals (copyFrom )) {
368
+ logger .info ("Moving " + copyFrom + " to: " + newLoc );
368
369
try {
369
- Files .move (f .toPath (), newLoc .toPath ());
370
+ // The move here needs to handle moving non-empty directories across NFS mounts
371
+ FileSystem fs = FileSystem .getLocal (_conf );
372
+ fs .rename (copyFrom , newLoc );
370
373
} catch (Exception e ) {
371
374
// Fail to move recovery file to new path, just continue on with new DB location
372
375
logger .error ("Failed to move recovery file {} to the path {}" ,
373
- dbFileName , _recoveryPath .toString (), e );
376
+ dbName , _recoveryPath .toString (), e );
374
377
}
375
378
}
376
- return newLoc ;
379
+ return new File ( newLoc . toUri (). getPath ()) ;
377
380
}
378
381
}
379
382
}
380
383
if (_recoveryPath == null ) {
381
384
_recoveryPath = new Path (localDirs [0 ]);
382
385
}
383
386
384
- return new File (_recoveryPath .toUri ().getPath (), dbFileName );
387
+ return new File (_recoveryPath .toUri ().getPath (), dbName );
385
388
}
386
389
387
390
/**
0 commit comments