@@ -293,6 +293,18 @@ public AzureBlobFileSystemStore(
293
293
"abfs-bounded" );
294
294
}
295
295
296
+ /**
297
+ * Updates the client with the namespace information.
298
+ *
299
+ * @param tracingContext the tracing context to be used for the operation
300
+ * @throws AzureBlobFileSystemException if an error occurs while updating the client
301
+ */
302
+ public void updateClientWithNamespaceInfo (TracingContext tracingContext )
303
+ throws AzureBlobFileSystemException {
304
+ boolean isNamespaceEnabled = getIsNamespaceEnabled (tracingContext );
305
+ AbfsClient .setIsNamespaceEnabled (isNamespaceEnabled );
306
+ }
307
+
296
308
/**
297
309
* Checks if the given key in Azure Storage should be stored as a page
298
310
* blob instead of block blob.
@@ -635,14 +647,15 @@ public OutputStream createFile(final Path path,
635
647
final FsPermission permission , final FsPermission umask ,
636
648
TracingContext tracingContext ) throws IOException {
637
649
try (AbfsPerfInfo perfInfo = startTracking ("createFile" , "createPath" )) {
650
+ AbfsClient createClient = getClientHandler ().getIngressClient ();
638
651
boolean isNamespaceEnabled = getIsNamespaceEnabled (tracingContext );
639
652
LOG .debug ("createFile filesystem: {} path: {} overwrite: {} permission: {} umask: {} isNamespaceEnabled: {}" ,
640
- getClient () .getFileSystem (),
641
- path ,
642
- overwrite ,
643
- permission ,
644
- umask ,
645
- isNamespaceEnabled );
653
+ createClient .getFileSystem (),
654
+ path ,
655
+ overwrite ,
656
+ permission ,
657
+ umask ,
658
+ isNamespaceEnabled );
646
659
647
660
String relativePath = getRelativePath (path );
648
661
boolean isAppendBlob = false ;
@@ -660,9 +673,9 @@ public OutputStream createFile(final Path path,
660
673
}
661
674
662
675
final ContextEncryptionAdapter contextEncryptionAdapter ;
663
- if (getClient () .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
676
+ if (createClient .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
664
677
contextEncryptionAdapter = new ContextProviderEncryptionAdapter (
665
- getClient () .getEncryptionContextProvider (), getRelativePath (path ));
678
+ createClient .getEncryptionContextProvider (), getRelativePath (path ));
666
679
} else {
667
680
contextEncryptionAdapter = NoContextEncryptionAdapter .getInstance ();
668
681
}
@@ -677,7 +690,7 @@ public OutputStream createFile(final Path path,
677
690
);
678
691
679
692
} else {
680
- op = getClient () .createPath (relativePath , true ,
693
+ op = createClient .createPath (relativePath , true ,
681
694
overwrite ,
682
695
new Permissions (isNamespaceEnabled , permission , umask ),
683
696
isAppendBlob ,
@@ -689,15 +702,16 @@ public OutputStream createFile(final Path path,
689
702
perfInfo .registerResult (op .getResult ()).registerSuccess (true );
690
703
691
704
AbfsLease lease = maybeCreateLease (relativePath , tracingContext );
692
-
705
+ String eTag = extractEtagHeader ( op . getResult ());
693
706
return new AbfsOutputStream (
694
707
populateAbfsOutputStreamContext (
695
708
isAppendBlob ,
696
709
lease ,
697
- getClient (),
710
+ getClientHandler (),
698
711
statistics ,
699
712
relativePath ,
700
713
0 ,
714
+ eTag ,
701
715
contextEncryptionAdapter ,
702
716
tracingContext ));
703
717
}
@@ -720,12 +734,12 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
720
734
final ContextEncryptionAdapter contextEncryptionAdapter ,
721
735
final TracingContext tracingContext ) throws IOException {
722
736
AbfsRestOperation op ;
723
-
737
+ AbfsClient createClient = getClientHandler (). getIngressClient ();
724
738
try {
725
739
// Trigger a create with overwrite=false first so that eTag fetch can be
726
740
// avoided for cases when no pre-existing file is present (major portion
727
741
// of create file traffic falls into the case of no pre-existing file).
728
- op = getClient () .createPath (relativePath , true , false , permissions ,
742
+ op = createClient .createPath (relativePath , true , false , permissions ,
729
743
isAppendBlob , null , contextEncryptionAdapter , tracingContext );
730
744
731
745
} catch (AbfsRestOperationException e ) {
@@ -745,12 +759,11 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
745
759
}
746
760
}
747
761
748
- String eTag = op .getResult ()
749
- .getResponseHeader (HttpHeaderConfigurations .ETAG );
762
+ String eTag = extractEtagHeader (op .getResult ());
750
763
751
764
try {
752
765
// overwrite only if eTag matches with the file properties fetched befpre
753
- op = getClient () .createPath (relativePath , true , true , permissions ,
766
+ op = createClient .createPath (relativePath , true , true , permissions ,
754
767
isAppendBlob , eTag , contextEncryptionAdapter , tracingContext );
755
768
} catch (AbfsRestOperationException ex ) {
756
769
if (ex .getStatusCode () == HttpURLConnection .HTTP_PRECON_FAILED ) {
@@ -778,22 +791,24 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
778
791
*
779
792
* @param isAppendBlob is Append blob support enabled?
780
793
* @param lease instance of AbfsLease for this AbfsOutputStream.
781
- * @param client AbfsClient .
794
+ * @param clientHandler AbfsClientHandler .
782
795
* @param statistics FileSystem statistics.
783
796
* @param path Path for AbfsOutputStream.
784
797
* @param position Position or offset of the file being opened, set to 0
785
798
* when creating a new file, but needs to be set for APPEND
786
799
* calls on the same file.
800
+ * @param eTag eTag of the file.
787
801
* @param tracingContext instance of TracingContext for this AbfsOutputStream.
788
802
* @return AbfsOutputStreamContext instance with the desired parameters.
789
803
*/
790
804
private AbfsOutputStreamContext populateAbfsOutputStreamContext (
791
805
boolean isAppendBlob ,
792
806
AbfsLease lease ,
793
- AbfsClient client ,
807
+ AbfsClientHandler clientHandler ,
794
808
FileSystem .Statistics statistics ,
795
809
String path ,
796
810
long position ,
811
+ String eTag ,
797
812
ContextEncryptionAdapter contextEncryptionAdapter ,
798
813
TracingContext tracingContext ) {
799
814
int bufferSize = abfsConfiguration .getWriteBufferSize ();
@@ -814,24 +829,38 @@ private AbfsOutputStreamContext populateAbfsOutputStreamContext(
814
829
.withEncryptionAdapter (contextEncryptionAdapter )
815
830
.withBlockFactory (getBlockFactory ())
816
831
.withBlockOutputActiveBlocks (blockOutputActiveBlocks )
817
- .withClient ( client )
832
+ .withClientHandler ( clientHandler )
818
833
.withPosition (position )
819
834
.withFsStatistics (statistics )
820
835
.withPath (path )
821
836
.withExecutorService (new SemaphoredDelegatingExecutor (boundedThreadPool ,
822
837
blockOutputActiveBlocks , true ))
823
838
.withTracingContext (tracingContext )
824
839
.withAbfsBackRef (fsBackRef )
840
+ .withIngressServiceType (abfsConfiguration .getIngressServiceType ())
841
+ .withDFSToBlobFallbackEnabled (abfsConfiguration .isDfsToBlobFallbackEnabled ())
842
+ .withETag (eTag )
825
843
.build ();
826
844
}
827
845
846
+ /**
847
+ * Creates a directory.
848
+ *
849
+ * @param path Path of the directory to create.
850
+ * @param permission Permission of the directory.
851
+ * @param umask Umask of the directory.
852
+ * @param tracingContext tracing context
853
+ *
854
+ * @throws AzureBlobFileSystemException server error.
855
+ */
828
856
public void createDirectory (final Path path , final FsPermission permission ,
829
857
final FsPermission umask , TracingContext tracingContext )
830
858
throws IOException {
831
859
try (AbfsPerfInfo perfInfo = startTracking ("createDirectory" , "createPath" )) {
860
+ AbfsClient createClient = getClientHandler ().getIngressClient ();
832
861
boolean isNamespaceEnabled = getIsNamespaceEnabled (tracingContext );
833
862
LOG .debug ("createDirectory filesystem: {} path: {} permission: {} umask: {} isNamespaceEnabled: {}" ,
834
- getClient () .getFileSystem (),
863
+ createClient .getFileSystem (),
835
864
path ,
836
865
permission ,
837
866
umask ,
@@ -841,7 +870,7 @@ public void createDirectory(final Path path, final FsPermission permission,
841
870
!isNamespaceEnabled || abfsConfiguration .isEnabledMkdirOverwrite ();
842
871
Permissions permissions = new Permissions (isNamespaceEnabled ,
843
872
permission , umask );
844
- final AbfsRestOperation op = getClient () .createPath (getRelativePath (path ),
873
+ final AbfsRestOperation op = createClient .createPath (getRelativePath (path ),
845
874
false , overwrite , permissions , false , null , null , tracingContext );
846
875
perfInfo .registerResult (op .getResult ()).registerSuccess (true );
847
876
}
@@ -976,6 +1005,7 @@ public OutputStream openFileForWrite(final Path path,
976
1005
overwrite );
977
1006
978
1007
String relativePath = getRelativePath (path );
1008
+ AbfsClient writeClient = getClientHandler ().getIngressClient ();
979
1009
980
1010
final AbfsRestOperation op = getClient ()
981
1011
.getPathStatus (relativePath , false , tracingContext , null );
@@ -1000,8 +1030,9 @@ public OutputStream openFileForWrite(final Path path,
1000
1030
}
1001
1031
1002
1032
AbfsLease lease = maybeCreateLease (relativePath , tracingContext );
1033
+ final String eTag = extractEtagHeader (op .getResult ());
1003
1034
final ContextEncryptionAdapter contextEncryptionAdapter ;
1004
- if (getClient () .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
1035
+ if (writeClient .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
1005
1036
final String encryptionContext = op .getResult ()
1006
1037
.getResponseHeader (
1007
1038
HttpHeaderConfigurations .X_MS_ENCRYPTION_CONTEXT );
@@ -1010,7 +1041,7 @@ public OutputStream openFileForWrite(final Path path,
1010
1041
"File doesn't have encryptionContext." );
1011
1042
}
1012
1043
contextEncryptionAdapter = new ContextProviderEncryptionAdapter (
1013
- getClient () .getEncryptionContextProvider (), getRelativePath (path ),
1044
+ writeClient .getEncryptionContextProvider (), getRelativePath (path ),
1014
1045
encryptionContext .getBytes (StandardCharsets .UTF_8 ));
1015
1046
} else {
1016
1047
contextEncryptionAdapter = NoContextEncryptionAdapter .getInstance ();
@@ -1020,10 +1051,11 @@ public OutputStream openFileForWrite(final Path path,
1020
1051
populateAbfsOutputStreamContext (
1021
1052
isAppendBlob ,
1022
1053
lease ,
1023
- getClient (),
1054
+ getClientHandler (),
1024
1055
statistics ,
1025
1056
relativePath ,
1026
1057
offset ,
1058
+ eTag ,
1027
1059
contextEncryptionAdapter ,
1028
1060
tracingContext ));
1029
1061
}
0 commit comments