Skip to content

Commit cb85a61

Browse files
authored
refactor: move put_multipart to ObjectStoreExt (#530)
See #385 and #405.
1 parent 179a087 commit cb85a61

File tree

12 files changed

+30
-52
lines changed

12 files changed

+30
-52
lines changed

src/aws/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//!
2020
//! ## Multipart uploads
2121
//!
22-
//! Multipart uploads can be initiated with the [ObjectStore::put_multipart] method.
22+
//! Multipart uploads can be initiated with the [`ObjectStore::put_multipart_opts`] method.
2323
//!
2424
//! If the writer fails for any reason, you may have parts uploaded to AWS but not
2525
//! used that you will be charged for. [`MultipartUpload::abort`] may be invoked to drop

src/azure/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//!
2020
//! ## Streaming uploads
2121
//!
22-
//! [ObjectStore::put_multipart] will upload data in blocks and write a blob from those blocks.
22+
//! [`ObjectStore::put_multipart_opts`] will upload data in blocks and write a blob from those blocks.
2323
//!
2424
//! Unused blocks will automatically be dropped after 7 days.
2525
use crate::{

src/buffered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ impl AsyncBufRead for BufReader {
211211
/// An async buffered writer compatible with the tokio IO traits
212212
///
213213
/// This writer adaptively uses [`ObjectStore::put_opts`] or
214-
/// [`ObjectStore::put_multipart`] depending on the amount of data that has
214+
/// [`ObjectStore::put_multipart_opts`] depending on the amount of data that has
215215
/// been written.
216216
///
217217
/// Up to `capacity` bytes will be buffered in memory, and flushed on shutdown
218218
/// using [`ObjectStore::put_opts`]. If `capacity` is exceeded, data will instead be
219-
/// streamed using [`ObjectStore::put_multipart`]
219+
/// streamed using [`ObjectStore::put_multipart_opts`].
220220
pub struct BufWriter {
221221
capacity: usize,
222222
max_concurrency: usize,
@@ -238,7 +238,7 @@ impl std::fmt::Debug for BufWriter {
238238
enum BufWriterState {
239239
/// Buffer up to capacity bytes
240240
Buffer(Path, PutPayloadMut),
241-
/// [`ObjectStore::put_multipart`]
241+
/// [`ObjectStore::put_multipart_opts`]
242242
Prepare(BoxFuture<'static, crate::Result<WriteMultipart>>),
243243
/// Write to a multipart upload
244244
Write(Option<WriteMultipart>),

src/chunked.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ impl ObjectStore for ChunkedStore {
7171
self.inner.put_opts(location, payload, opts).await
7272
}
7373

74-
async fn put_multipart(&self, location: &Path) -> Result<Box<dyn MultipartUpload>> {
75-
self.inner.put_multipart(location).await
76-
}
77-
7874
async fn put_multipart_opts(
7975
&self,
8076
location: &Path,

src/gcp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! ## Multipart uploads
2121
//!
2222
//! [Multipart uploads](https://cloud.google.com/storage/docs/multipart-uploads)
23-
//! can be initiated with the [ObjectStore::put_multipart] method. If neither
23+
//! can be initiated with the [`ObjectStore::put_multipart_opts`] method. If neither
2424
//! [`MultipartUpload::complete`] nor [`MultipartUpload::abort`] is invoked, you may
2525
//! have parts uploaded to GCS but not used, that you will be charged for. It is recommended
2626
//! you configure a [lifecycle rule] to abort incomplete multipart uploads after a certain

src/lib.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,12 @@
273273
//!
274274
//! # Multipart Upload
275275
//!
276-
//! Use the [`ObjectStore::put_multipart`] method to atomically write a large amount of data
276+
//! Use the [`ObjectStoreExt::put_multipart`] / [`ObjectStore::put_multipart_opts`] method to atomically write a large
277+
//! amount of data
277278
//!
278279
//! ```ignore-wasm32
279280
//! # use object_store::local::LocalFileSystem;
280-
//! # use object_store::{ObjectStore, WriteMultipart};
281+
//! # use object_store::{ObjectStore, ObjectStoreExt, WriteMultipart};
281282
//! # use std::sync::Arc;
282283
//! # use bytes::Bytes;
283284
//! # use tokio::io::AsyncWriteExt;
@@ -638,17 +639,6 @@ pub trait ObjectStore: std::fmt::Display + Send + Sync + Debug + 'static {
638639
opts: PutOptions,
639640
) -> Result<PutResult>;
640641

641-
/// Perform a multipart upload
642-
///
643-
/// Client should prefer [`ObjectStoreExt::put`] for small payloads, as streaming uploads
644-
/// typically require multiple separate requests. See [`MultipartUpload`] for more information
645-
///
646-
/// For more advanced multipart uploads see [`MultipartStore`](multipart::MultipartStore)
647-
async fn put_multipart(&self, location: &Path) -> Result<Box<dyn MultipartUpload>> {
648-
self.put_multipart_opts(location, PutMultipartOptions::default())
649-
.await
650-
}
651-
652642
/// Perform a multipart upload with options
653643
///
654644
/// Client should prefer [`ObjectStore::put_opts`] for small payloads, as streaming uploads
@@ -1117,10 +1107,6 @@ macro_rules! as_ref_impl {
11171107
self.as_ref().put_opts(location, payload, opts).await
11181108
}
11191109

1120-
async fn put_multipart(&self, location: &Path) -> Result<Box<dyn MultipartUpload>> {
1121-
self.as_ref().put_multipart(location).await
1122-
}
1123-
11241110
async fn put_multipart_opts(
11251111
&self,
11261112
location: &Path,
@@ -1202,7 +1188,7 @@ macro_rules! as_ref_impl {
12021188
as_ref_impl!(Arc<dyn ObjectStore>);
12031189
as_ref_impl!(Box<dyn ObjectStore>);
12041190

1205-
/// Extension trait for [`ObjectStore`] with convinience functions.
1191+
/// Extension trait for [`ObjectStore`] with convenience functions.
12061192
///
12071193
/// See "contract" section within the [`ObjectStore`] documentation for more reasoning.
12081194
///
@@ -1215,6 +1201,17 @@ pub trait ObjectStoreExt: ObjectStore {
12151201
/// write the entirety of `payload` to `location`, or fail. No clients
12161202
/// should be able to observe a partially written object
12171203
fn put(&self, location: &Path, payload: PutPayload) -> impl Future<Output = Result<PutResult>>;
1204+
1205+
/// Perform a multipart upload
1206+
///
1207+
/// Client should prefer [`ObjectStoreExt::put`] for small payloads, as streaming uploads
1208+
/// typically require multiple separate requests. See [`MultipartUpload`] for more information
1209+
///
1210+
/// For more advanced multipart uploads see [`MultipartStore`](multipart::MultipartStore)
1211+
fn put_multipart(
1212+
&self,
1213+
location: &Path,
1214+
) -> impl Future<Output = Result<Box<dyn MultipartUpload>>>;
12181215
}
12191216

12201217
impl<T> ObjectStoreExt for T
@@ -1225,6 +1222,11 @@ where
12251222
self.put_opts(location, payload, PutOptions::default())
12261223
.await
12271224
}
1225+
1226+
async fn put_multipart(&self, location: &Path) -> Result<Box<dyn MultipartUpload>> {
1227+
self.put_multipart_opts(location, PutMultipartOptions::default())
1228+
.await
1229+
}
12281230
}
12291231

12301232
/// Result of a list call that includes objects, prefixes (directories) and a

src/limit.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ impl<T: ObjectStore> ObjectStore for LimitStore<T> {
8080
let _permit = self.semaphore.acquire().await.unwrap();
8181
self.inner.put_opts(location, payload, opts).await
8282
}
83-
async fn put_multipart(&self, location: &Path) -> Result<Box<dyn MultipartUpload>> {
84-
let upload = self.inner.put_multipart(location).await?;
85-
Ok(Box::new(LimitUpload {
86-
semaphore: Arc::clone(&self.semaphore),
87-
upload,
88-
}))
89-
}
9083

9184
async fn put_multipart_opts(
9285
&self,

src/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ mod not_wasm_tests {
17191719
use tempfile::TempDir;
17201720

17211721
use crate::local::LocalFileSystem;
1722-
use crate::{ObjectStore, Path, PutPayload};
1722+
use crate::{ObjectStoreExt, Path, PutPayload};
17231723

17241724
#[tokio::test]
17251725
async fn test_cleanup_intermediate_files() {

src/multipart.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ pub struct PartId {
3535

3636
/// A low-level interface for interacting with multipart upload APIs
3737
///
38-
/// Most use-cases should prefer [`ObjectStore::put_multipart`] as this is supported by more
38+
/// Most use-cases should prefer [`ObjectStore::put_multipart_opts`] as this is supported by more
3939
/// backends, including [`LocalFileSystem`], and automatically handles uploading fixed
4040
/// size parts of sufficient size in parallel
4141
///
42-
/// [`ObjectStore::put_multipart`]: crate::ObjectStore::put_multipart
42+
/// [`ObjectStore::put_multipart_opts`]: crate::ObjectStore::put_multipart_opts
4343
/// [`LocalFileSystem`]: crate::local::LocalFileSystem
4444
#[async_trait]
4545
pub trait MultipartStore: Send + Sync + 'static {

src/prefix.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ impl<T: ObjectStore> ObjectStore for PrefixStore<T> {
104104
self.inner.put_opts(&full_path, payload, opts).await
105105
}
106106

107-
async fn put_multipart(&self, location: &Path) -> Result<Box<dyn MultipartUpload>> {
108-
let full_path = self.full_path(location);
109-
self.inner.put_multipart(&full_path).await
110-
}
111-
112107
async fn put_multipart_opts(
113108
&self,
114109
location: &Path,

0 commit comments

Comments
 (0)