Samrose-Ahmed commented on code in PR #5205:
URL: https://github.com/apache/arrow-rs/pull/5205#discussion_r1427292516
##########
object_store/src/multipart.rs:
##########
@@ -316,3 +317,136 @@ pub trait MultiPartStore: Send + Sync + 'static {
/// Aborts a multipart upload
async fn abort_multipart(&self, path: &Path, id: &MultipartId) ->
Result<()>;
}
+
+/// Create a lazy multipart writer for a given [`ObjectStore`] and [`Path`].
+pub fn put_multipart_lazy(
+ store: Arc<dyn ObjectStore>,
+ path: Path,
+) -> Box<dyn AsyncWrite + Send + Unpin> {
+ Box::new(LazyWriteMultiPart::new(store, path))
+}
+
+/// Wrapper around a [`ObjectStore`] and [`Path`] that implements
[`AsyncWrite`]
+///
+/// A multipart upload using `ObjectStore::put_multipart` will only be created
if the size exceeds 10 MB,
+/// otherwise a direct PUT will be performed on shutdown.
+pub struct LazyWriteMultiPart {
+ store: Arc<dyn ObjectStore>,
+ path: Path,
+ part_size: usize,
+ multipart_writer: Option<Box<dyn AsyncWrite + Send + Unpin>>,
+ buffer: Vec<u8>,
+ create_task: Option<BoxedTryFuture<Box<dyn AsyncWrite + Send + Unpin>>>,
+ put_task: Option<BoxedTryFuture<()>>,
+}
+
+impl LazyWriteMultiPart {
+ /// Create a new lazy multipart upload.
+ pub fn new(store: Arc<dyn ObjectStore>, path: Path) -> Self {
+ Self {
+ store,
+ path,
+ part_size: 10 * 1024 * 1024,
+ multipart_writer: None,
+ buffer: Vec::new(),
+ create_task: None,
+ put_task: None,
+ }
+ }
+
+ fn do_flush(
+ mut self: Pin<&mut Self>,
+ cx: &mut std::task::Context<'_>,
+ ) -> Poll<Result<(), io::Error>> {
+ let buffer = std::mem::take(&mut self.buffer);
Review Comment:
I tried to but I was having ownership issues. Also do we have to handle the
same case you mentioned below here as well where the poll_write doesnt accept
the buffer, right?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]