@@ -396,6 +396,10 @@ public Path getLocalPathForWrite(String pathStr, long size,
396396 Context ctx = confChanged (conf );
397397 int numDirs = ctx .localDirs .length ;
398398 int numDirsSearched = 0 ;
399+ // Max capacity in any directory
400+ long maxCapacity = 0 ;
401+ String errorText = null ;
402+ IOException diskException = null ;
399403 //remove the leading slash from the path (to make sure that the uri
400404 //resolution results in a valid path on the dir being checked)
401405 if (pathStr .startsWith ("/" )) {
@@ -444,9 +448,18 @@ public Path getLocalPathForWrite(String pathStr, long size,
444448 int dirNum = ctx .getAndIncrDirNumLastAccessed (randomInc );
445449 while (numDirsSearched < numDirs ) {
446450 long capacity = ctx .dirDF [dirNum ].getAvailable ();
451+ if (capacity > maxCapacity ) {
452+ maxCapacity = capacity ;
453+ }
447454 if (capacity > size ) {
448- returnPath =
449- createPath (ctx .localDirs [dirNum ], pathStr , checkWrite );
455+ try {
456+ returnPath = createPath (ctx .localDirs [dirNum ], pathStr ,
457+ checkWrite );
458+ } catch (IOException e ) {
459+ errorText = e .getMessage ();
460+ diskException = e ;
461+ LOG .debug ("DiskException caught for dir {}" , ctx .localDirs [dirNum ], e );
462+ }
450463 if (returnPath != null ) {
451464 ctx .getAndIncrDirNumLastAccessed (numDirsSearched );
452465 break ;
@@ -462,8 +475,13 @@ public Path getLocalPathForWrite(String pathStr, long size,
462475 }
463476
464477 //no path found
465- throw new DiskErrorException ("Could not find any valid local " +
466- "directory for " + pathStr );
478+ String newErrorText = "Could not find any valid local directory for " +
479+ pathStr + " with requested size " + size +
480+ " as the max capacity in any directory is " + maxCapacity ;
481+ if (errorText != null ) {
482+ newErrorText = newErrorText + " due to " + errorText ;
483+ }
484+ throw new DiskErrorException (newErrorText , diskException );
467485 }
468486
469487 /** Creates a file on the local FS. Pass size as
0 commit comments