You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/06/29 15:15:47 UTC

[incubator-opendal] branch main updated: feat(services/azblob): support sink (#2574)

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/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 1deb08779 feat(services/azblob): support sink (#2574)
1deb08779 is described below

commit 1deb0877918e6beeeb74ceedb5f6a2207d97f99e
Author: Suyan <su...@gmail.com>
AuthorDate: Thu Jun 29 23:15:40 2023 +0800

    feat(services/azblob): support sink (#2574)
    
    * feat(services/azblob): support sink
    
    Signed-off-by: suyanhanx <su...@gmail.com>
    
    * polish
    
    Signed-off-by: suyanhanx <su...@gmail.com>
    
    ---------
    
    Signed-off-by: suyanhanx <su...@gmail.com>
---
 core/src/services/azblob/backend.rs |  1 +
 core/src/services/azblob/core.rs    |  2 +-
 core/src/services/azblob/writer.rs  | 24 +++++++++++++-----------
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/core/src/services/azblob/backend.rs b/core/src/services/azblob/backend.rs
index 7df1c52e9..b635f0203 100644
--- a/core/src/services/azblob/backend.rs
+++ b/core/src/services/azblob/backend.rs
@@ -531,6 +531,7 @@ impl Accessor for AzblobBackend {
                 read_with_override_content_disposition: true,
 
                 write: true,
+                write_can_sink: true,
                 write_with_cache_control: true,
                 write_with_content_type: true,
 
diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs
index 9142cbae8..e15910828 100644
--- a/core/src/services/azblob/core.rs
+++ b/core/src/services/azblob/core.rs
@@ -244,7 +244,7 @@ impl AzblobCore {
     pub fn azblob_put_blob_request(
         &self,
         path: &str,
-        size: Option<usize>,
+        size: Option<u64>,
         content_type: Option<&str>,
         cache_control: Option<&str>,
         body: AsyncBody,
diff --git a/core/src/services/azblob/writer.rs b/core/src/services/azblob/writer.rs
index b751f5590..b8d4dc644 100644
--- a/core/src/services/azblob/writer.rs
+++ b/core/src/services/azblob/writer.rs
@@ -37,17 +37,14 @@ impl AzblobWriter {
     pub fn new(core: Arc<AzblobCore>, op: OpWrite, path: String) -> Self {
         AzblobWriter { core, op, path }
     }
-}
 
-#[async_trait]
-impl oio::Write for AzblobWriter {
-    async fn write(&mut self, bs: Bytes) -> Result<()> {
+    async fn write_oneshot(&self, size: u64, body: AsyncBody) -> Result<()> {
         let mut req = self.core.azblob_put_blob_request(
             &self.path,
-            Some(bs.len()),
+            Some(size),
             self.op.content_type(),
             self.op.cache_control(),
-            AsyncBody::Bytes(bs),
+            body,
         )?;
 
         self.core.sign(&mut req).await?;
@@ -64,12 +61,17 @@ impl oio::Write for AzblobWriter {
             _ => Err(parse_error(resp).await?),
         }
     }
+}
+
+#[async_trait]
+impl oio::Write for AzblobWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {
+        self.write_oneshot(bs.len() as u64, AsyncBody::Bytes(bs))
+            .await
+    }
 
-    async fn sink(&mut self, _size: u64, _s: oio::Streamer) -> Result<()> {
-        Err(Error::new(
-            ErrorKind::Unsupported,
-            "Write::sink is not supported",
-        ))
+    async fn sink(&mut self, size: u64, s: oio::Streamer) -> Result<()> {
+        self.write_oneshot(size, AsyncBody::Stream(s)).await
     }
 
     async fn abort(&mut self) -> Result<()> {