8383import static java .net .HttpURLConnection .HTTP_NOT_FOUND ;
8484import static java .net .HttpURLConnection .HTTP_OK ;
8585import static java .net .HttpURLConnection .HTTP_PRECON_FAILED ;
86- import static org .apache .hadoop .fs .azurebfs .AzureBlobFileSystemStore .extractEtagHeader ;
8786import static org .apache .hadoop .fs .azurebfs .AbfsStatistic .CALL_GET_FILE_STATUS ;
87+ import static org .apache .hadoop .fs .azurebfs .AzureBlobFileSystemStore .extractEtagHeader ;
8888import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .ACQUIRE_LEASE_ACTION ;
8989import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .AND_MARK ;
9090import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .APPEND_BLOB_TYPE ;
@@ -424,7 +424,7 @@ private void fixAtomicEntriesInListResults(final AbfsRestOperation op,
424424 }
425425 List <BlobListResultEntrySchema > filteredEntries = new ArrayList <>();
426426 for (BlobListResultEntrySchema entry : listResultSchema .paths ()) {
427- if (!takeListPathAtomicRenameKeyAction (entry .path (),
427+ if (!takeListPathAtomicRenameKeyAction (entry .path (), entry . isDirectory (),
428428 entry .contentLength ().intValue (), tracingContext )) {
429429 filteredEntries .add (entry );
430430 }
@@ -442,17 +442,19 @@ public void createNonRecursivePreCheck(Path parentPath,
442442 if (isAtomicRenameKey (parentPath .toUri ().getPath ())) {
443443 takeGetPathStatusAtomicRenameKeyAction (parentPath , tracingContext );
444444 }
445- getPathStatus (parentPath .toUri ().getPath (), false ,
446- tracingContext , null );
445+ try {
446+ getPathStatus (parentPath .toUri ().getPath (), false ,
447+ tracingContext , null );
448+ } finally {
449+ getAbfsCounters ().incrementCounter (CALL_GET_FILE_STATUS , 1 );
450+ }
447451 } catch (AbfsRestOperationException ex ) {
448452 if (ex .getStatusCode () == HttpURLConnection .HTTP_NOT_FOUND ) {
449453 throw new FileNotFoundException ("Cannot create file "
450454 + parentPath .toUri ().getPath ()
451455 + " because parent folder does not exist." );
452456 }
453457 throw ex ;
454- } finally {
455- getAbfsCounters ().incrementCounter (CALL_GET_FILE_STATUS , 1 );
456458 }
457459 }
458460
@@ -807,23 +809,26 @@ public AbfsClientRenameResult renamePath(final String source,
807809 BlobRenameHandler blobRenameHandler = getBlobRenameHandler (source ,
808810 destination , sourceEtag , isAtomicRenameKey (source ), tracingContext
809811 );
810- incrementAbfsRenamePath ();
811- if (blobRenameHandler .execute ()) {
812- final AbfsUriQueryBuilder abfsUriQueryBuilder
813- = createDefaultUriQueryBuilder ();
814- final URL url = createRequestUrl (destination ,
815- abfsUriQueryBuilder .toString ());
816- final List <AbfsHttpHeader > requestHeaders = createDefaultHeaders ();
817- final AbfsRestOperation successOp = getSuccessOp (
818- AbfsRestOperationType .RenamePath , HTTP_METHOD_PUT ,
819- url , requestHeaders );
820- return new AbfsClientRenameResult (successOp , true , false );
821- } else {
822- throw new AbfsRestOperationException (HTTP_INTERNAL_ERROR ,
823- AzureServiceErrorCode .UNKNOWN .getErrorCode (),
824- ERR_RENAME_BLOB + source + SINGLE_WHITE_SPACE + AND_MARK
825- + SINGLE_WHITE_SPACE + destination ,
826- null );
812+ try {
813+ if (blobRenameHandler .execute ()) {
814+ final AbfsUriQueryBuilder abfsUriQueryBuilder
815+ = createDefaultUriQueryBuilder ();
816+ final URL url = createRequestUrl (destination ,
817+ abfsUriQueryBuilder .toString ());
818+ final List <AbfsHttpHeader > requestHeaders = createDefaultHeaders ();
819+ final AbfsRestOperation successOp = getSuccessOp (
820+ AbfsRestOperationType .RenamePath , HTTP_METHOD_PUT ,
821+ url , requestHeaders );
822+ return new AbfsClientRenameResult (successOp , true , false );
823+ } else {
824+ throw new AbfsRestOperationException (HTTP_INTERNAL_ERROR ,
825+ AzureServiceErrorCode .UNKNOWN .getErrorCode (),
826+ ERR_RENAME_BLOB + source + SINGLE_WHITE_SPACE + AND_MARK
827+ + SINGLE_WHITE_SPACE + destination ,
828+ null );
829+ }
830+ } finally {
831+ incrementAbfsRenamePath ();
827832 }
828833 }
829834
@@ -1801,11 +1806,11 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
18011806 * @throws AzureBlobFileSystemException server error
18021807 */
18031808 private boolean takeListPathAtomicRenameKeyAction (final Path path ,
1804- final int renamePendingJsonLen ,
1809+ final boolean isDirectory , final int renamePendingJsonLen ,
18051810 final TracingContext tracingContext )
18061811 throws AzureBlobFileSystemException {
18071812 if (path == null || path .isRoot () || !isAtomicRenameKey (
1808- path .toUri ().getPath ()) || !path .toUri ()
1813+ path .toUri ().getPath ()) || isDirectory || !path .toUri ()
18091814 .getPath ()
18101815 .endsWith (RenameAtomicity .SUFFIX )) {
18111816 return false ;
@@ -1833,7 +1838,7 @@ private boolean takeListPathAtomicRenameKeyAction(final Path path,
18331838 }
18341839
18351840 @ VisibleForTesting
1836- RenameAtomicity getRedoRenameAtomicity (final Path renamePendingJsonPath ,
1841+ public RenameAtomicity getRedoRenameAtomicity (final Path renamePendingJsonPath ,
18371842 int fileLen ,
18381843 final TracingContext tracingContext ) {
18391844 return new RenameAtomicity (renamePendingJsonPath ,
0 commit comments