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/21 10:58:10 UTC

[incubator-opendal] 01/05: Save work

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch implement-sink-for-s3
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit a0cb2e8a1c1b5e75da3ece154c857aa8bae7b4b6
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Mon Jun 12 20:06:44 2023 +0800

    Save work
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/src/services/s3/core.rs   |  2 +-
 core/src/services/s3/writer.rs | 24 +++++++++++++++---------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/core/src/services/s3/core.rs b/core/src/services/s3/core.rs
index c802fd430..18746399b 100644
--- a/core/src/services/s3/core.rs
+++ b/core/src/services/s3/core.rs
@@ -321,7 +321,7 @@ impl S3Core {
     pub fn s3_put_object_request(
         &self,
         path: &str,
-        size: Option<usize>,
+        size: Option<u64>,
         content_type: Option<&str>,
         content_disposition: Option<&str>,
         cache_control: Option<&str>,
diff --git a/core/src/services/s3/writer.rs b/core/src/services/s3/writer.rs
index 320a9ec0e..2ef197e43 100644
--- a/core/src/services/s3/writer.rs
+++ b/core/src/services/s3/writer.rs
@@ -54,14 +54,14 @@ impl S3Writer {
         }
     }
 
-    async fn write_oneshot(&self, bs: Bytes) -> Result<()> {
+    async fn write_oneshot(&self, size: u64, body: AsyncBody) -> Result<()> {
         let mut req = self.core.s3_put_object_request(
             &self.path,
-            Some(bs.len()),
+            Some(size),
             self.op.content_type(),
             self.op.content_disposition(),
             self.op.cache_control(),
-            AsyncBody::Bytes(bs),
+            body,
         )?;
 
         self.core.sign(&mut req).await?;
@@ -154,7 +154,9 @@ impl oio::Write for S3Writer {
             Some(upload_id) => upload_id,
             None => {
                 if self.op.content_length().unwrap_or_default() == bs.len() as u64 {
-                    return self.write_oneshot(bs).await;
+                    return self
+                        .write_oneshot(bs.len() as u64, AsyncBody::Bytes(bs))
+                        .await;
                 } else {
                     let upload_id = self.initiate_upload().await?;
                     self.upload_id = Some(upload_id);
@@ -192,11 +194,15 @@ impl oio::Write for S3Writer {
         }
     }
 
-    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<()> {
+        if self.op.content_length().unwrap_or_default() == size {
+            return self.write_oneshot(size, AsyncBody::Stream(s)).await;
+        } else {
+            return Err(Error::new(
+                ErrorKind::Unsupported,
+                "S3 does not support streaming multipart upload",
+            ));
+        }
     }
 
     async fn abort(&mut self) -> Result<()> {