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 2024/01/09 07:13:59 UTC

(incubator-opendal) 01/01: Try AFIT

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

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

commit 230dda4fa69aac47c214b6b30430f94197e649bf
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Tue Jan 9 15:13:49 2024 +0800

    Try AFIT
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/src/raw/oio/write/multipart_upload_write.rs | 44 +++++++++++++++++++-----
 core/src/services/b2/writer.rs                   |  2 --
 core/src/services/cos/writer.rs                  |  1 -
 core/src/services/obs/writer.rs                  |  1 -
 core/src/services/oss/writer.rs                  |  1 -
 core/src/services/s3/writer.rs                   |  3 --
 core/src/services/upyun/writer.rs                |  2 --
 7 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/core/src/raw/oio/write/multipart_upload_write.rs b/core/src/raw/oio/write/multipart_upload_write.rs
index 66105b4d4a..729bdb2c32 100644
--- a/core/src/raw/oio/write/multipart_upload_write.rs
+++ b/core/src/raw/oio/write/multipart_upload_write.rs
@@ -21,7 +21,6 @@ use std::task::ready;
 use std::task::Context;
 use std::task::Poll;
 
-use async_trait::async_trait;
 use futures::Future;
 use futures::FutureExt;
 use futures::StreamExt;
@@ -51,15 +50,16 @@ use crate::*;
 /// ```
 ///
 /// We will use `write_once` instead of starting a new multipart upload.
-#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
-#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
 pub trait MultipartUploadWrite: Send + Sync + Unpin + 'static {
     /// write_once is used to write the data to underlying storage at once.
     ///
     /// MultipartUploadWriter will call this API when:
     ///
     /// - All the data has been written to the buffer and we can perform the upload at once.
-    async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()>;
+    #[cfg(not(target_arch = "wasm32"))]
+    fn write_once(&self, size: u64, body: AsyncBody) -> impl Future<Output = Result<()>> + Send;
+    #[cfg(target_arch = "wasm32")]
+    fn write_once(&self, size: u64, body: AsyncBody) -> impl Future<Output = Result<()>>;
 
     /// initiate_part will call start a multipart upload and return the upload id.
     ///
@@ -68,7 +68,10 @@ pub trait MultipartUploadWrite: Send + Sync + Unpin + 'static {
     /// - the total size of data is unknown.
     /// - the total size of data is known, but the size of current write
     /// is less then the total size.
-    async fn initiate_part(&self) -> Result<String>;
+    #[cfg(not(target_arch = "wasm32"))]
+    fn initiate_part(&self) -> impl Future<Output = Result<String>> + Send;
+    #[cfg(target_arch = "wasm32")]
+    fn initiate_part(&self) -> impl Future<Output = Result<String>>;
 
     /// write_part will write a part of the data and returns the result
     /// [`MultipartUploadPart`].
@@ -77,20 +80,43 @@ pub trait MultipartUploadWrite: Send + Sync + Unpin + 'static {
     /// order.
     ///
     /// - part_number is the index of the part, starting from 0.
-    async fn write_part(
+    #[cfg(not(target_arch = "wasm32"))]
+    fn write_part(
         &self,
         upload_id: &str,
         part_number: usize,
         size: u64,
         body: AsyncBody,
-    ) -> Result<MultipartUploadPart>;
+    ) -> impl Future<Output = Result<MultipartUploadPart>> + Send;
+    #[cfg(target_arch = "wasm32")]
+    fn write_part(
+        &self,
+        upload_id: &str,
+        part_number: usize,
+        size: u64,
+        body: AsyncBody,
+    ) -> impl Future<Output = Result<MultipartUploadPart>>;
 
     /// complete_part will complete the multipart upload to build the final
     /// file.
-    async fn complete_part(&self, upload_id: &str, parts: &[MultipartUploadPart]) -> Result<()>;
+    #[cfg(not(target_arch = "wasm32"))]
+    fn complete_part(
+        &self,
+        upload_id: &str,
+        parts: &[MultipartUploadPart],
+    ) -> impl Future<Output = Result<()>> + Send;
+    #[cfg(target_arch = "wasm32")]
+    fn complete_part(
+        &self,
+        upload_id: &str,
+        parts: &[MultipartUploadPart],
+    ) -> impl Future<Output = Result<()>>;
 
     /// abort_part will cancel the multipart upload and purge all data.
-    async fn abort_part(&self, upload_id: &str) -> Result<()>;
+    #[cfg(not(target_arch = "wasm32"))]
+    fn abort_part(&self, upload_id: &str) -> impl Future<Output = Result<()>> + Send;
+    #[cfg(target_arch = "wasm32")]
+    fn abort_part(&self, upload_id: &str) -> impl Future<Output = Result<()>>;
 }
 
 /// The result of [`MultipartUploadWrite::write_part`].
diff --git a/core/src/services/b2/writer.rs b/core/src/services/b2/writer.rs
index 59f4367fb5..6dbca97607 100644
--- a/core/src/services/b2/writer.rs
+++ b/core/src/services/b2/writer.rs
@@ -17,7 +17,6 @@
 
 use std::sync::Arc;
 
-use async_trait::async_trait;
 use http::StatusCode;
 
 use super::core::B2Core;
@@ -46,7 +45,6 @@ impl B2Writer {
     }
 }
 
-#[async_trait]
 impl oio::MultipartUploadWrite for B2Writer {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
         let resp = self
diff --git a/core/src/services/cos/writer.rs b/core/src/services/cos/writer.rs
index b1d1dbac50..c236e12d01 100644
--- a/core/src/services/cos/writer.rs
+++ b/core/src/services/cos/writer.rs
@@ -45,7 +45,6 @@ impl CosWriter {
     }
 }
 
-#[async_trait]
 impl oio::MultipartUploadWrite for CosWriter {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
         let mut req = self
diff --git a/core/src/services/obs/writer.rs b/core/src/services/obs/writer.rs
index 1dff95eda1..900e66d98f 100644
--- a/core/src/services/obs/writer.rs
+++ b/core/src/services/obs/writer.rs
@@ -46,7 +46,6 @@ impl ObsWriter {
     }
 }
 
-#[async_trait]
 impl oio::MultipartUploadWrite for ObsWriter {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
         let mut req = self
diff --git a/core/src/services/oss/writer.rs b/core/src/services/oss/writer.rs
index 1770ffeb64..45254a454c 100644
--- a/core/src/services/oss/writer.rs
+++ b/core/src/services/oss/writer.rs
@@ -45,7 +45,6 @@ impl OssWriter {
     }
 }
 
-#[async_trait]
 impl oio::MultipartUploadWrite for OssWriter {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
         let mut req =
diff --git a/core/src/services/s3/writer.rs b/core/src/services/s3/writer.rs
index 22ecc041ab..c116f574c2 100644
--- a/core/src/services/s3/writer.rs
+++ b/core/src/services/s3/writer.rs
@@ -17,7 +17,6 @@
 
 use std::sync::Arc;
 
-use async_trait::async_trait;
 use http::StatusCode;
 
 use super::core::*;
@@ -44,8 +43,6 @@ impl S3Writer {
     }
 }
 
-#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
-#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
 impl oio::MultipartUploadWrite for S3Writer {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
         let mut req = self
diff --git a/core/src/services/upyun/writer.rs b/core/src/services/upyun/writer.rs
index b4f5082122..10793b58e5 100644
--- a/core/src/services/upyun/writer.rs
+++ b/core/src/services/upyun/writer.rs
@@ -17,7 +17,6 @@
 
 use std::sync::Arc;
 
-use async_trait::async_trait;
 use http::StatusCode;
 
 use super::core::constants::X_UPYUN_MULTI_UUID;
@@ -40,7 +39,6 @@ impl UpyunWriter {
     }
 }
 
-#[async_trait]
 impl oio::MultipartUploadWrite for UpyunWriter {
     async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
         let req = self