This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 989746e06 refactor(services/azblob): Refactor raw request send in
writer (#6102)
989746e06 is described below
commit 989746e06cced8a9905a9b2998ad6188fdf919ef
Author: Jorge Hermo <[email protected]>
AuthorDate: Sun Apr 27 15:59:31 2025 +0200
refactor(services/azblob): Refactor raw request send in writer (#6102)
---
core/src/services/azblob/core.rs | 45 ++++++++++++++++++++++++++++++++++----
core/src/services/azblob/writer.rs | 28 +++++++++---------------
2 files changed, 51 insertions(+), 22 deletions(-)
diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs
index 017876ba1..594f48362 100644
--- a/core/src/services/azblob/core.rs
+++ b/core/src/services/azblob/core.rs
@@ -294,6 +294,19 @@ impl AzblobCore {
Ok(req)
}
+ pub async fn azblob_put_blob(
+ &self,
+ path: &str,
+ size: Option<u64>,
+ args: &OpWrite,
+ body: Buffer,
+ ) -> Result<Response<Buffer>> {
+ let mut req = self.azblob_put_blob_request(path, size, args, body)?;
+
+ self.sign(&mut req).await?;
+ self.send(req).await
+ }
+
/// For appendable object, it could be created by `put` an empty blob
/// with `x-ms-blob-type` header set to `AppendBlob`.
/// And it's just initialized with empty content.
@@ -311,7 +324,7 @@ impl AzblobCore {
/// # Reference
///
/// https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob
- pub fn azblob_init_appendable_blob_request(
+ fn azblob_init_appendable_blob_request(
&self,
path: &str,
args: &OpWrite,
@@ -342,6 +355,17 @@ impl AzblobCore {
Ok(req)
}
+ pub async fn azblob_init_appendable_blob(
+ &self,
+ path: &str,
+ args: &OpWrite,
+ ) -> Result<Response<Buffer>> {
+ let mut req = self.azblob_init_appendable_blob_request(path, args)?;
+
+ self.sign(&mut req).await?;
+ self.send(req).await
+ }
+
/// Append content to an appendable blob.
/// The content will be appended to the end of the blob.
///
@@ -353,7 +377,7 @@ impl AzblobCore {
/// # Reference
///
/// https://learn.microsoft.com/en-us/rest/api/storageservices/append-block
- pub fn azblob_append_blob_request(
+ fn azblob_append_blob_request(
&self,
path: &str,
position: u64,
@@ -376,6 +400,19 @@ impl AzblobCore {
Ok(req)
}
+ pub async fn azblob_append_blob(
+ &self,
+ path: &str,
+ position: u64,
+ size: u64,
+ body: Buffer,
+ ) -> Result<Response<Buffer>> {
+ let mut req = self.azblob_append_blob_request(path, position, size,
body)?;
+
+ self.sign(&mut req).await?;
+ self.send(req).await
+ }
+
pub fn azblob_put_block_request(
&self,
path: &str,
@@ -428,7 +465,7 @@ impl AzblobCore {
self.send(req).await
}
- pub fn azblob_complete_put_block_list_request(
+ fn azblob_complete_put_block_list_request(
&self,
path: &str,
block_ids: Vec<Uuid>,
@@ -507,7 +544,7 @@ impl AzblobCore {
self.send(req).await
}
- pub fn azblob_delete_blob_request(&self, path: &str) ->
Result<Request<Buffer>> {
+ fn azblob_delete_blob_request(&self, path: &str) ->
Result<Request<Buffer>> {
let req = Request::delete(self.build_path_url(path));
req.header(CONTENT_LENGTH, 0)
diff --git a/core/src/services/azblob/writer.rs
b/core/src/services/azblob/writer.rs
index d67b43e5a..ffda2cdb7 100644
--- a/core/src/services/azblob/writer.rs
+++ b/core/src/services/azblob/writer.rs
@@ -86,13 +86,10 @@ impl oio::AppendWrite for AzblobWriter {
Ok(parse_content_length(headers)?.unwrap_or_default())
}
StatusCode::NOT_FOUND => {
- let mut req = self
+ let resp = self
.core
- .azblob_init_appendable_blob_request(&self.path,
&self.op)?;
-
- self.core.sign(&mut req).await?;
-
- let resp = self.core.info.http_client().send(req).await?;
+ .azblob_init_appendable_blob(&self.path, &self.op)
+ .await?;
let status = resp.status();
match status {
@@ -110,13 +107,10 @@ impl oio::AppendWrite for AzblobWriter {
}
async fn append(&self, offset: u64, size: u64, body: Buffer) ->
Result<Metadata> {
- let mut req = self
+ let resp = self
.core
- .azblob_append_blob_request(&self.path, offset, size, body)?;
-
- self.core.sign(&mut req).await?;
-
- let resp = self.core.send(req).await?;
+ .azblob_append_blob(&self.path, offset, size, body)
+ .await?;
let meta = AzblobWriter::parse_metadata(resp.headers())?;
let status = resp.status();
@@ -129,12 +123,10 @@ impl oio::AppendWrite for AzblobWriter {
impl oio::BlockWrite for AzblobWriter {
async fn write_once(&self, size: u64, body: Buffer) -> Result<Metadata> {
- let mut req: http::Request<Buffer> =
- self.core
- .azblob_put_blob_request(&self.path, Some(size), &self.op,
body)?;
- self.core.sign(&mut req).await?;
-
- let resp = self.core.send(req).await?;
+ let resp = self
+ .core
+ .azblob_put_blob(&self.path, Some(size), &self.op, body)
+ .await?;
let status = resp.status();