You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "suyanhanx (via GitHub)" <gi...@apache.org> on 2023/07/24 08:11:07 UTC
[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2699: feat(oio): Add MultipartUploadWrite to easier the work for Writer
suyanhanx commented on code in PR #2699:
URL: https://github.com/apache/incubator-opendal/pull/2699#discussion_r1271893497
##########
core/src/raw/oio/write/multipart_upload_write.rs:
##########
@@ -0,0 +1,265 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use async_trait::async_trait;
+use bytes::Bytes;
+
+use crate::{raw::*, *};
+
+const DEFAULT_WRITE_MIN_SIZE: usize = 8 * 1024 * 1024;
+
+/// MultipartUploadWrite is used to implement [`Write`] based on multipart
+/// uploads. By implementing MultipartUploadWrite, services don't need to
+/// care about the details of buffering and uploading parts.
+///
+/// The layout after adopting [`MultipartUploadWrite`]:
+///
+/// - Services impl `MultipartUploadWrite`
+/// - `MultipartUploadWriter` impl `Write`
+/// - Expose `MultipartUploadWriter` as `Accessor::Writer`
+#[async_trait]
+pub trait MultipartUploadWrite: Send + Sync + Unpin {
+ /// write_once write all data at once.
+ ///
+ /// MultipartUploadWriter will call this API when the size of data is
+ /// already known.
+ async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()>;
+
+ /// initiate_part will call start a multipart upload and return the upload id.
+ ///
+ /// MultipartUploadWriter will call this when:
+ ///
+ /// - 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>;
+
+ /// write_part will write a part of the data and returns the result
+ /// [`MultipartUploadPart`].
+ ///
+ /// MultipartUploadWriter will call this API and stores the result in
+ /// order.
+ ///
+ /// - part_number is the index of the part, starting from 0.
+ async fn write_part(
+ &self,
+ upload_id: &str,
+ part_number: usize,
+ size: u64,
+ body: AsyncBody,
+ ) -> 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<()>;
+
+ /// abort_part will cancel the multipart upload and purge all data.
+ async fn abort_part(&self, upload_id: &str) -> Result<()>;
+}
+
+/// The result of [`MultipartUploadWrite::write_part`].
+///
+/// services implement should convert MultipartUploadPart to their own represents.
+///
+/// - `part_number` is the index of the part, starting from 0.
+/// - `etag` is the `ETag` of the part.
+pub struct MultipartUploadPart {
+ /// The numbder of the part, starting from 0.
Review Comment:
```suggestion
/// The number of the part, starting from 0.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org