28
28
import java .net .URISyntaxException ;
29
29
import java .nio .file .AccessDeniedException ;
30
30
import java .time .Duration ;
31
- import java .util .Hashtable ;
32
- import java .util .List ;
33
31
import java .util .ArrayList ;
34
32
import java .util .EnumSet ;
33
+ import java .util .Hashtable ;
34
+ import java .util .List ;
35
35
import java .util .Map ;
36
36
import java .util .Optional ;
37
37
import java .util .UUID ;
43
43
import java .util .concurrent .Future ;
44
44
import javax .annotation .Nullable ;
45
45
46
- import org .apache .commons .lang3 .StringUtils ;
47
- import org .apache .hadoop .classification .VisibleForTesting ;
48
- import org .apache .hadoop .fs .azurebfs .contracts .exceptions .InvalidConfigurationValueException ;
49
- import org .apache .hadoop .fs .azurebfs .services .AuthType ;
50
- import org .apache .hadoop .fs .impl .BackReference ;
51
- import org .apache .hadoop .security .ProviderUtils ;
52
- import org .apache .hadoop .util .Preconditions ;
53
46
import org .slf4j .Logger ;
54
47
import org .slf4j .LoggerFactory ;
48
+
55
49
import org .apache .commons .lang3 .ArrayUtils ;
50
+ import org .apache .commons .lang3 .StringUtils ;
56
51
import org .apache .commons .lang3 .tuple .Pair ;
57
52
import org .apache .hadoop .classification .InterfaceAudience ;
58
- import org .apache .hadoop .fs .azurebfs .commit .ResilientCommitByRename ;
59
- import org .apache .hadoop .fs .azurebfs .services .AbfsClient ;
60
- import org .apache .hadoop .fs .azurebfs .services .AbfsListStatusRemoteIterator ;
61
- import org .apache .hadoop .fs .RemoteIterator ;
62
53
import org .apache .hadoop .classification .InterfaceStability ;
54
+ import org .apache .hadoop .classification .VisibleForTesting ;
63
55
import org .apache .hadoop .conf .Configuration ;
64
56
import org .apache .hadoop .fs .BlockLocation ;
65
57
import org .apache .hadoop .fs .CommonPathCapabilities ;
71
63
import org .apache .hadoop .fs .FileSystem ;
72
64
import org .apache .hadoop .fs .LocatedFileStatus ;
73
65
import org .apache .hadoop .fs .Path ;
74
- import org .apache .hadoop .fs .PathIOException ;
75
66
import org .apache .hadoop .fs .PathFilter ;
67
+ import org .apache .hadoop .fs .PathIOException ;
68
+ import org .apache .hadoop .fs .RemoteIterator ;
76
69
import org .apache .hadoop .fs .XAttrSetFlag ;
70
+ import org .apache .hadoop .fs .azurebfs .commit .ResilientCommitByRename ;
77
71
import org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants ;
72
+ import org .apache .hadoop .fs .azurebfs .constants .FSOperationType ;
78
73
import org .apache .hadoop .fs .azurebfs .constants .FileSystemConfigurations ;
79
74
import org .apache .hadoop .fs .azurebfs .constants .FileSystemUriSchemes ;
80
- import org .apache .hadoop .fs .azurebfs .constants .FSOperationType ;
81
75
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .AbfsRestOperationException ;
82
76
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .AzureBlobFileSystemException ;
83
77
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .FileSystemOperationUnhandledException ;
78
+ import org .apache .hadoop .fs .azurebfs .contracts .exceptions .InvalidConfigurationValueException ;
84
79
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .InvalidUriAuthorityException ;
85
80
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .InvalidUriException ;
86
81
import org .apache .hadoop .fs .azurebfs .contracts .exceptions .SASTokenProviderException ;
87
82
import org .apache .hadoop .fs .azurebfs .contracts .services .AzureServiceErrorCode ;
88
83
import org .apache .hadoop .fs .azurebfs .security .AbfsDelegationTokenManager ;
84
+ import org .apache .hadoop .fs .azurebfs .services .AbfsClient ;
89
85
import org .apache .hadoop .fs .azurebfs .services .AbfsCounters ;
86
+ import org .apache .hadoop .fs .azurebfs .services .AbfsListStatusRemoteIterator ;
90
87
import org .apache .hadoop .fs .azurebfs .services .AbfsLocatedFileStatus ;
88
+ import org .apache .hadoop .fs .azurebfs .services .AuthType ;
91
89
import org .apache .hadoop .fs .azurebfs .utils .Listener ;
92
90
import org .apache .hadoop .fs .azurebfs .utils .TracingContext ;
93
91
import org .apache .hadoop .fs .azurebfs .utils .TracingHeaderFormat ;
94
92
import org .apache .hadoop .fs .impl .AbstractFSBuilderImpl ;
93
+ import org .apache .hadoop .fs .impl .BackReference ;
95
94
import org .apache .hadoop .fs .impl .OpenFileParameters ;
96
95
import org .apache .hadoop .fs .permission .AclEntry ;
97
96
import org .apache .hadoop .fs .permission .AclStatus ;
102
101
import org .apache .hadoop .fs .store .DataBlocks ;
103
102
import org .apache .hadoop .io .IOUtils ;
104
103
import org .apache .hadoop .security .AccessControlException ;
105
- import org .apache .hadoop .security .token . Token ;
104
+ import org .apache .hadoop .security .ProviderUtils ;
106
105
import org .apache .hadoop .security .UserGroupInformation ;
107
- import org .apache .hadoop .util .RateLimiting ;
108
- import org .apache .hadoop .util .RateLimitingFactory ;
109
- import org .apache .hadoop .util .functional .RemoteIterators ;
106
+ import org .apache .hadoop .security .token .Token ;
110
107
import org .apache .hadoop .util .DurationInfo ;
111
108
import org .apache .hadoop .util .LambdaUtils ;
109
+ import org .apache .hadoop .util .Preconditions ;
112
110
import org .apache .hadoop .util .Progressable ;
111
+ import org .apache .hadoop .util .RateLimiting ;
112
+ import org .apache .hadoop .util .RateLimitingFactory ;
113
+ import org .apache .hadoop .util .functional .RemoteIterators ;
113
114
114
115
import static java .net .HttpURLConnection .HTTP_BAD_REQUEST ;
115
116
import static java .net .HttpURLConnection .HTTP_CONFLICT ;
@@ -431,8 +432,12 @@ public FSDataOutputStream create(final Path f,
431
432
432
433
@ Override
433
434
@ SuppressWarnings ("deprecation" )
434
- public FSDataOutputStream createNonRecursive (final Path f , final FsPermission permission ,
435
- final boolean overwrite , final int bufferSize , final short replication , final long blockSize ,
435
+ public FSDataOutputStream createNonRecursive (final Path f ,
436
+ final FsPermission permission ,
437
+ final boolean overwrite ,
438
+ final int bufferSize ,
439
+ final short replication ,
440
+ final long blockSize ,
436
441
final Progressable progress ) throws IOException {
437
442
438
443
statIncrement (CALL_CREATE_NON_RECURSIVE );
@@ -442,18 +447,21 @@ public FSDataOutputStream createNonRecursive(final Path f, final FsPermission pe
442
447
ERR_CREATE_ON_ROOT ,
443
448
null );
444
449
}
445
- final Path parent = f .getParent ();
446
- TracingContext tracingContext = new TracingContext (clientCorrelationId ,
447
- fileSystemId , FSOperationType .CREATE_NON_RECURSIVE , tracingHeaderFormat ,
448
- listener );
449
- final FileStatus parentFileStatus = tryGetFileStatus (parent , tracingContext );
450
-
451
- if (parentFileStatus == null ) {
452
- throw new FileNotFoundException ("Cannot create file "
453
- + f .getName () + " because parent folder does not exist." );
450
+ Path qualifiedPath = makeQualified (f );
451
+ try {
452
+ TracingContext tracingContext = new TracingContext (clientCorrelationId ,
453
+ fileSystemId , FSOperationType .CREATE_NON_RECURSIVE , tracingHeaderFormat ,
454
+ listener );
455
+ OutputStream outputStream = getAbfsStore ().createNonRecursive (qualifiedPath , statistics ,
456
+ overwrite ,
457
+ permission == null ? FsPermission .getFileDefault () : permission ,
458
+ FsPermission .getUMask (getConf ()), tracingContext );
459
+ statIncrement (FILES_CREATED );
460
+ return new FSDataOutputStream (outputStream , statistics );
461
+ } catch (AzureBlobFileSystemException ex ) {
462
+ checkException (f , ex );
463
+ return null ;
454
464
}
455
-
456
- return create (f , permission , overwrite , bufferSize , replication , blockSize , progress );
457
465
}
458
466
459
467
@ Override
@@ -480,7 +488,10 @@ public FSDataOutputStream createNonRecursive(final Path f,
480
488
@ Override
481
489
@ SuppressWarnings ("deprecation" )
482
490
public FSDataOutputStream createNonRecursive (final Path f ,
483
- final boolean overwrite , final int bufferSize , final short replication , final long blockSize ,
491
+ final boolean overwrite ,
492
+ final int bufferSize ,
493
+ final short replication ,
494
+ final long blockSize ,
484
495
final Progressable progress ) throws IOException {
485
496
return this .createNonRecursive (f , FsPermission .getFileDefault (),
486
497
overwrite , bufferSize , replication , blockSize , progress );
@@ -530,45 +541,41 @@ public boolean rename(final Path src, final Path dst) throws IOException {
530
541
return tryGetFileStatus (qualifiedSrcPath , tracingContext ) != null ;
531
542
}
532
543
533
- FileStatus dstFileStatus = null ;
544
+ FileStatus dstFileStatus = tryGetFileStatus (qualifiedDstPath , tracingContext );
545
+ Path adjustedDst = dst ;
534
546
if (qualifiedSrcPath .equals (qualifiedDstPath )) {
535
547
// rename to itself
536
548
// - if it doesn't exist, return false
537
549
// - if it is file, return true
538
550
// - if it is dir, return false.
539
- dstFileStatus = tryGetFileStatus (qualifiedDstPath , tracingContext );
540
551
if (dstFileStatus == null ) {
541
552
return false ;
542
553
}
543
- return dstFileStatus .isDirectory () ? false : true ;
554
+ return ! dstFileStatus .isDirectory ();
544
555
}
545
-
546
- // Non-HNS account need to check dst status on driver side.
547
- if (!getIsNamespaceEnabled (tracingContext ) && dstFileStatus == null ) {
548
- dstFileStatus = tryGetFileStatus (qualifiedDstPath , tracingContext );
556
+ // adjust the destination path in case of FNS account.
557
+ if (!getIsNamespaceEnabled (tracingContext ) && dstFileStatus != null ) {
558
+ // return false if the destination is a file.
559
+ if (!dstFileStatus .isDirectory ()) {
560
+ return false ;
561
+ }
562
+ String sourceFileName = src .getName ();
563
+ adjustedDst = new Path (dst , sourceFileName );
549
564
}
550
565
551
566
try {
552
- String sourceFileName = src .getName ();
553
- Path adjustedDst = dst ;
554
-
555
- if (dstFileStatus != null ) {
556
- if (!dstFileStatus .isDirectory ()) {
557
- return qualifiedSrcPath .equals (qualifiedDstPath );
558
- }
559
- adjustedDst = new Path (dst , sourceFileName );
560
- }
561
-
562
567
qualifiedDstPath = makeQualified (adjustedDst );
563
-
564
- abfsStore . rename ( qualifiedSrcPath , qualifiedDstPath , tracingContext , null );
568
+ getAbfsStore (). rename ( qualifiedSrcPath , qualifiedDstPath , tracingContext ,
569
+ null );
565
570
return true ;
566
571
} catch (AzureBlobFileSystemException ex ) {
567
572
LOG .debug ("Rename operation failed. " , ex );
568
573
checkException (
569
574
src ,
570
575
ex ,
571
576
AzureServiceErrorCode .PATH_ALREADY_EXISTS ,
577
+ AzureServiceErrorCode .BLOB_ALREADY_EXISTS ,
578
+ AzureServiceErrorCode .BLOB_PATH_NOT_FOUND ,
572
579
AzureServiceErrorCode .INVALID_RENAME_SOURCE_PATH ,
573
580
AzureServiceErrorCode .SOURCE_PATH_NOT_FOUND ,
574
581
AzureServiceErrorCode .INVALID_SOURCE_OR_DESTINATION_RESOURCE_TYPE ,
@@ -641,7 +648,7 @@ public Pair<Boolean, Duration> commitSingleFileByRename(
641
648
final Duration waitTime = rateLimiting .acquire (1 );
642
649
643
650
try {
644
- final boolean recovered = abfsStore .rename (qualifiedSrcPath ,
651
+ final boolean recovered = getAbfsStore () .rename (qualifiedSrcPath ,
645
652
qualifiedDstPath , tracingContext , sourceEtag );
646
653
return Pair .of (recovered , waitTime );
647
654
} catch (AzureBlobFileSystemException ex ) {
@@ -655,9 +662,11 @@ public Pair<Boolean, Duration> commitSingleFileByRename(
655
662
}
656
663
657
664
@ Override
658
- public boolean delete (final Path f , final boolean recursive ) throws IOException {
665
+ public boolean delete (final Path f , final boolean recursive )
666
+ throws IOException {
659
667
LOG .debug (
660
- "AzureBlobFileSystem.delete path: {} recursive: {}" , f .toString (), recursive );
668
+ "AzureBlobFileSystem.delete path: {} recursive: {}" , f .toString (),
669
+ recursive );
661
670
statIncrement (CALL_DELETE );
662
671
Path qualifiedPath = makeQualified (f );
663
672
@@ -673,10 +682,13 @@ public boolean delete(final Path f, final boolean recursive) throws IOException
673
682
TracingContext tracingContext = new TracingContext (clientCorrelationId ,
674
683
fileSystemId , FSOperationType .DELETE , tracingHeaderFormat ,
675
684
listener );
676
- abfsStore .delete (qualifiedPath , recursive , tracingContext );
685
+ getAbfsStore () .delete (qualifiedPath , recursive , tracingContext );
677
686
return true ;
678
687
} catch (AzureBlobFileSystemException ex ) {
679
- checkException (f , ex , AzureServiceErrorCode .PATH_NOT_FOUND );
688
+ checkException (f ,
689
+ ex ,
690
+ AzureServiceErrorCode .PATH_NOT_FOUND ,
691
+ AzureServiceErrorCode .BLOB_PATH_NOT_FOUND );
680
692
return false ;
681
693
}
682
694
@@ -693,7 +705,7 @@ public FileStatus[] listStatus(final Path f) throws IOException {
693
705
TracingContext tracingContext = new TracingContext (clientCorrelationId ,
694
706
fileSystemId , FSOperationType .LISTSTATUS , true , tracingHeaderFormat ,
695
707
listener );
696
- FileStatus [] result = abfsStore .listStatus (qualifiedPath , tracingContext );
708
+ FileStatus [] result = getAbfsStore () .listStatus (qualifiedPath , tracingContext );
697
709
return result ;
698
710
} catch (AzureBlobFileSystemException ex ) {
699
711
checkException (f , ex );
0 commit comments