You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by su...@apache.org on 2023/05/08 15:52:24 UTC

[incubator-opendal] branch gcs-writer-abort created (now a1617cf4)

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

suyanhanx pushed a change to branch gcs-writer-abort
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


      at a1617cf4 feat(services/gcs): writer abort

This branch includes the following new commits:

     new a1617cf4 feat(services/gcs): writer abort

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-opendal] 01/01: feat(services/gcs): writer abort

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

suyanhanx pushed a commit to branch gcs-writer-abort
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit a1617cf4a08c315bee69f30406d1c83eccae70d7
Author: suyanhanx <su...@gmail.com>
AuthorDate: Mon May 8 23:52:01 2023 +0800

    feat(services/gcs): writer abort
    
    Signed-off-by: suyanhanx <su...@gmail.com>
---
 core/src/services/gcs/core.rs   | 14 ++++++++++++++
 core/src/services/gcs/writer.rs | 20 ++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/core/src/services/gcs/core.rs b/core/src/services/gcs/core.rs
index 5ac9dc20..7ebe25db 100644
--- a/core/src/services/gcs/core.rs
+++ b/core/src/services/gcs/core.rs
@@ -538,4 +538,18 @@ impl GcsCore {
 
         self.send(req).await
     }
+
+    pub async fn gcs_abort_resumable_upload(
+        &self,
+        location: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = Request::delete(location)
+            .header(CONTENT_LENGTH, 0)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)?;
+
+        self.sign(&mut req).await?;
+
+        self.send(req).await
+    }
 }
diff --git a/core/src/services/gcs/writer.rs b/core/src/services/gcs/writer.rs
index e853de83..36e851f6 100644
--- a/core/src/services/gcs/writer.rs
+++ b/core/src/services/gcs/writer.rs
@@ -163,9 +163,25 @@ impl oio::Write for GcsWriter {
         }
     }
 
-    // TODO: we can cancel the upload by sending a DELETE request to the location
     async fn abort(&mut self) -> Result<()> {
-        Ok(())
+        let location = if let Some(location) = &self.location {
+            location
+        } else {
+            return Ok(());
+        };
+
+        let resp = self.core.gcs_abort_resumable_upload(location).await?;
+
+        match resp.status() {
+            // gcs returns 204 if the upload aborted successfully
+            StatusCode::NO_CONTENT => {
+                resp.into_body().consume().await?;
+                self.location = None;
+                self.buffer.clear();
+                Ok(())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
     }
 
     async fn close(&mut self) -> Result<()> {