83
83
import static java .net .HttpURLConnection .HTTP_NOT_FOUND ;
84
84
import static java .net .HttpURLConnection .HTTP_OK ;
85
85
import static java .net .HttpURLConnection .HTTP_PRECON_FAILED ;
86
- import static org .apache .hadoop .fs .azurebfs .AzureBlobFileSystemStore .extractEtagHeader ;
87
86
import static org .apache .hadoop .fs .azurebfs .AbfsStatistic .CALL_GET_FILE_STATUS ;
87
+ import static org .apache .hadoop .fs .azurebfs .AzureBlobFileSystemStore .extractEtagHeader ;
88
88
import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .ACQUIRE_LEASE_ACTION ;
89
89
import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .AND_MARK ;
90
90
import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .APPEND_BLOB_TYPE ;
@@ -424,7 +424,7 @@ private void fixAtomicEntriesInListResults(final AbfsRestOperation op,
424
424
}
425
425
List <BlobListResultEntrySchema > filteredEntries = new ArrayList <>();
426
426
for (BlobListResultEntrySchema entry : listResultSchema .paths ()) {
427
- if (!takeListPathAtomicRenameKeyAction (entry .path (),
427
+ if (!takeListPathAtomicRenameKeyAction (entry .path (), entry . isDirectory (),
428
428
entry .contentLength ().intValue (), tracingContext )) {
429
429
filteredEntries .add (entry );
430
430
}
@@ -442,17 +442,19 @@ public void createNonRecursivePreCheck(Path parentPath,
442
442
if (isAtomicRenameKey (parentPath .toUri ().getPath ())) {
443
443
takeGetPathStatusAtomicRenameKeyAction (parentPath , tracingContext );
444
444
}
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
+ }
447
451
} catch (AbfsRestOperationException ex ) {
448
452
if (ex .getStatusCode () == HttpURLConnection .HTTP_NOT_FOUND ) {
449
453
throw new FileNotFoundException ("Cannot create file "
450
454
+ parentPath .toUri ().getPath ()
451
455
+ " because parent folder does not exist." );
452
456
}
453
457
throw ex ;
454
- } finally {
455
- getAbfsCounters ().incrementCounter (CALL_GET_FILE_STATUS , 1 );
456
458
}
457
459
}
458
460
@@ -807,23 +809,26 @@ public AbfsClientRenameResult renamePath(final String source,
807
809
BlobRenameHandler blobRenameHandler = getBlobRenameHandler (source ,
808
810
destination , sourceEtag , isAtomicRenameKey (source ), tracingContext
809
811
);
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 ();
827
832
}
828
833
}
829
834
@@ -1817,11 +1822,11 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
1817
1822
* @throws AzureBlobFileSystemException server error
1818
1823
*/
1819
1824
private boolean takeListPathAtomicRenameKeyAction (final Path path ,
1820
- final int renamePendingJsonLen ,
1825
+ final boolean isDirectory , final int renamePendingJsonLen ,
1821
1826
final TracingContext tracingContext )
1822
1827
throws AzureBlobFileSystemException {
1823
1828
if (path == null || path .isRoot () || !isAtomicRenameKey (
1824
- path .toUri ().getPath ()) || !path .toUri ()
1829
+ path .toUri ().getPath ()) || isDirectory || !path .toUri ()
1825
1830
.getPath ()
1826
1831
.endsWith (RenameAtomicity .SUFFIX )) {
1827
1832
return false ;
@@ -1849,7 +1854,7 @@ private boolean takeListPathAtomicRenameKeyAction(final Path path,
1849
1854
}
1850
1855
1851
1856
@ VisibleForTesting
1852
- RenameAtomicity getRedoRenameAtomicity (final Path renamePendingJsonPath ,
1857
+ public RenameAtomicity getRedoRenameAtomicity (final Path renamePendingJsonPath ,
1853
1858
int fileLen ,
1854
1859
final TracingContext tracingContext ) {
1855
1860
return new RenameAtomicity (renamePendingJsonPath ,
0 commit comments