@@ -293,6 +293,18 @@ public AzureBlobFileSystemStore(
293293 "abfs-bounded" );
294294 }
295295
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+
296308 /**
297309 * Checks if the given key in Azure Storage should be stored as a page
298310 * blob instead of block blob.
@@ -635,14 +647,15 @@ public OutputStream createFile(final Path path,
635647 final FsPermission permission , final FsPermission umask ,
636648 TracingContext tracingContext ) throws IOException {
637649 try (AbfsPerfInfo perfInfo = startTracking ("createFile" , "createPath" )) {
650+ AbfsClient createClient = getClientHandler ().getIngressClient ();
638651 boolean isNamespaceEnabled = getIsNamespaceEnabled (tracingContext );
639652 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 );
646659
647660 String relativePath = getRelativePath (path );
648661 boolean isAppendBlob = false ;
@@ -660,9 +673,9 @@ public OutputStream createFile(final Path path,
660673 }
661674
662675 final ContextEncryptionAdapter contextEncryptionAdapter ;
663- if (getClient () .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
676+ if (createClient .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
664677 contextEncryptionAdapter = new ContextProviderEncryptionAdapter (
665- getClient () .getEncryptionContextProvider (), getRelativePath (path ));
678+ createClient .getEncryptionContextProvider (), getRelativePath (path ));
666679 } else {
667680 contextEncryptionAdapter = NoContextEncryptionAdapter .getInstance ();
668681 }
@@ -677,7 +690,7 @@ public OutputStream createFile(final Path path,
677690 );
678691
679692 } else {
680- op = getClient () .createPath (relativePath , true ,
693+ op = createClient .createPath (relativePath , true ,
681694 overwrite ,
682695 new Permissions (isNamespaceEnabled , permission , umask ),
683696 isAppendBlob ,
@@ -689,15 +702,16 @@ public OutputStream createFile(final Path path,
689702 perfInfo .registerResult (op .getResult ()).registerSuccess (true );
690703
691704 AbfsLease lease = maybeCreateLease (relativePath , tracingContext );
692-
705+ String eTag = extractEtagHeader ( op . getResult ());
693706 return new AbfsOutputStream (
694707 populateAbfsOutputStreamContext (
695708 isAppendBlob ,
696709 lease ,
697- getClient (),
710+ getClientHandler (),
698711 statistics ,
699712 relativePath ,
700713 0 ,
714+ eTag ,
701715 contextEncryptionAdapter ,
702716 tracingContext ));
703717 }
@@ -720,12 +734,12 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
720734 final ContextEncryptionAdapter contextEncryptionAdapter ,
721735 final TracingContext tracingContext ) throws IOException {
722736 AbfsRestOperation op ;
723-
737+ AbfsClient createClient = getClientHandler (). getIngressClient ();
724738 try {
725739 // Trigger a create with overwrite=false first so that eTag fetch can be
726740 // avoided for cases when no pre-existing file is present (major portion
727741 // 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 ,
729743 isAppendBlob , null , contextEncryptionAdapter , tracingContext );
730744
731745 } catch (AbfsRestOperationException e ) {
@@ -745,12 +759,11 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
745759 }
746760 }
747761
748- String eTag = op .getResult ()
749- .getResponseHeader (HttpHeaderConfigurations .ETAG );
762+ String eTag = extractEtagHeader (op .getResult ());
750763
751764 try {
752765 // 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 ,
754767 isAppendBlob , eTag , contextEncryptionAdapter , tracingContext );
755768 } catch (AbfsRestOperationException ex ) {
756769 if (ex .getStatusCode () == HttpURLConnection .HTTP_PRECON_FAILED ) {
@@ -778,22 +791,24 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
778791 *
779792 * @param isAppendBlob is Append blob support enabled?
780793 * @param lease instance of AbfsLease for this AbfsOutputStream.
781- * @param client AbfsClient .
794+ * @param clientHandler AbfsClientHandler .
782795 * @param statistics FileSystem statistics.
783796 * @param path Path for AbfsOutputStream.
784797 * @param position Position or offset of the file being opened, set to 0
785798 * when creating a new file, but needs to be set for APPEND
786799 * calls on the same file.
800+ * @param eTag eTag of the file.
787801 * @param tracingContext instance of TracingContext for this AbfsOutputStream.
788802 * @return AbfsOutputStreamContext instance with the desired parameters.
789803 */
790804 private AbfsOutputStreamContext populateAbfsOutputStreamContext (
791805 boolean isAppendBlob ,
792806 AbfsLease lease ,
793- AbfsClient client ,
807+ AbfsClientHandler clientHandler ,
794808 FileSystem .Statistics statistics ,
795809 String path ,
796810 long position ,
811+ String eTag ,
797812 ContextEncryptionAdapter contextEncryptionAdapter ,
798813 TracingContext tracingContext ) {
799814 int bufferSize = abfsConfiguration .getWriteBufferSize ();
@@ -814,24 +829,38 @@ private AbfsOutputStreamContext populateAbfsOutputStreamContext(
814829 .withEncryptionAdapter (contextEncryptionAdapter )
815830 .withBlockFactory (getBlockFactory ())
816831 .withBlockOutputActiveBlocks (blockOutputActiveBlocks )
817- .withClient ( client )
832+ .withClientHandler ( clientHandler )
818833 .withPosition (position )
819834 .withFsStatistics (statistics )
820835 .withPath (path )
821836 .withExecutorService (new SemaphoredDelegatingExecutor (boundedThreadPool ,
822837 blockOutputActiveBlocks , true ))
823838 .withTracingContext (tracingContext )
824839 .withAbfsBackRef (fsBackRef )
840+ .withIngressServiceType (abfsConfiguration .getIngressServiceType ())
841+ .withDFSToBlobFallbackEnabled (abfsConfiguration .isDfsToBlobFallbackEnabled ())
842+ .withETag (eTag )
825843 .build ();
826844 }
827845
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+ */
828856 public void createDirectory (final Path path , final FsPermission permission ,
829857 final FsPermission umask , TracingContext tracingContext )
830858 throws IOException {
831859 try (AbfsPerfInfo perfInfo = startTracking ("createDirectory" , "createPath" )) {
860+ AbfsClient createClient = getClientHandler ().getIngressClient ();
832861 boolean isNamespaceEnabled = getIsNamespaceEnabled (tracingContext );
833862 LOG .debug ("createDirectory filesystem: {} path: {} permission: {} umask: {} isNamespaceEnabled: {}" ,
834- getClient () .getFileSystem (),
863+ createClient .getFileSystem (),
835864 path ,
836865 permission ,
837866 umask ,
@@ -841,7 +870,7 @@ public void createDirectory(final Path path, final FsPermission permission,
841870 !isNamespaceEnabled || abfsConfiguration .isEnabledMkdirOverwrite ();
842871 Permissions permissions = new Permissions (isNamespaceEnabled ,
843872 permission , umask );
844- final AbfsRestOperation op = getClient () .createPath (getRelativePath (path ),
873+ final AbfsRestOperation op = createClient .createPath (getRelativePath (path ),
845874 false , overwrite , permissions , false , null , null , tracingContext );
846875 perfInfo .registerResult (op .getResult ()).registerSuccess (true );
847876 }
@@ -976,6 +1005,7 @@ public OutputStream openFileForWrite(final Path path,
9761005 overwrite );
9771006
9781007 String relativePath = getRelativePath (path );
1008+ AbfsClient writeClient = getClientHandler ().getIngressClient ();
9791009
9801010 final AbfsRestOperation op = getClient ()
9811011 .getPathStatus (relativePath , false , tracingContext , null );
@@ -1000,8 +1030,9 @@ public OutputStream openFileForWrite(final Path path,
10001030 }
10011031
10021032 AbfsLease lease = maybeCreateLease (relativePath , tracingContext );
1033+ final String eTag = extractEtagHeader (op .getResult ());
10031034 final ContextEncryptionAdapter contextEncryptionAdapter ;
1004- if (getClient () .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
1035+ if (writeClient .getEncryptionType () == EncryptionType .ENCRYPTION_CONTEXT ) {
10051036 final String encryptionContext = op .getResult ()
10061037 .getResponseHeader (
10071038 HttpHeaderConfigurations .X_MS_ENCRYPTION_CONTEXT );
@@ -1010,7 +1041,7 @@ public OutputStream openFileForWrite(final Path path,
10101041 "File doesn't have encryptionContext." );
10111042 }
10121043 contextEncryptionAdapter = new ContextProviderEncryptionAdapter (
1013- getClient () .getEncryptionContextProvider (), getRelativePath (path ),
1044+ writeClient .getEncryptionContextProvider (), getRelativePath (path ),
10141045 encryptionContext .getBytes (StandardCharsets .UTF_8 ));
10151046 } else {
10161047 contextEncryptionAdapter = NoContextEncryptionAdapter .getInstance ();
@@ -1020,10 +1051,11 @@ public OutputStream openFileForWrite(final Path path,
10201051 populateAbfsOutputStreamContext (
10211052 isAppendBlob ,
10221053 lease ,
1023- getClient (),
1054+ getClientHandler (),
10241055 statistics ,
10251056 relativePath ,
10261057 offset ,
1058+ eTag ,
10271059 contextEncryptionAdapter ,
10281060 tracingContext ));
10291061 }
0 commit comments