@@ -26,20 +26,19 @@ use tokio_util::compat::{FuturesAsyncReadCompatExt, FuturesAsyncWriteCompatExt};
2626use crate :: metrics:: object_storage_get_slice_in_flight_guards;
2727use crate :: storage:: SendableAsync ;
2828use crate :: {
29- BulkDeleteError , OwnedBytes , PutPayload , Storage , StorageError , StorageErrorKind ,
30- StorageResolverError , StorageResult ,
29+ BulkDeleteError , MultiPartPolicy , OwnedBytes , PutPayload , Storage , StorageError ,
30+ StorageErrorKind , StorageResolverError , StorageResult ,
3131} ;
3232
3333/// OpenDAL based storage implementation.
3434/// # TODO
3535///
3636/// - Implement REQUEST_SEMAPHORE to control the concurrency.
3737/// - Implement STORAGE_METRICS for metrics.
38- /// - Add multipart_policy to control write at once or via multiple.
39- #[ derive( Clone ) ]
4038pub struct OpendalStorage {
4139 uri : Uri ,
4240 op : Operator ,
41+ multipart_policy : MultiPartPolicy ,
4342}
4443
4544impl fmt:: Debug for OpendalStorage {
@@ -58,7 +57,16 @@ impl OpendalStorage {
5857 cfg : opendal:: services:: Gcs ,
5958 ) -> Result < Self , StorageResolverError > {
6059 let op = Operator :: new ( cfg) ?. finish ( ) ;
61- Ok ( Self { uri, op } )
60+ Ok ( Self {
61+ uri,
62+ op,
63+ // limits are the same as on S3
64+ multipart_policy : MultiPartPolicy :: default ( ) ,
65+ } )
66+ }
67+
68+ pub fn set_policy ( & mut self , multipart_policy : MultiPartPolicy ) {
69+ self . multipart_policy = multipart_policy;
6270 }
6371}
6472
@@ -69,17 +77,14 @@ impl Storage for OpendalStorage {
6977 Ok ( ( ) )
7078 }
7179
72- /// # TODO
73- ///
74- /// We can implement something like `multipart_policy` determine whether to use copy.
75- /// If the payload is small enough, we can call `op.write()` at once.
7680 async fn put ( & self , path : & Path , payload : Box < dyn PutPayload > ) -> StorageResult < ( ) > {
7781 let path = path. as_os_str ( ) . to_string_lossy ( ) ;
7882 let mut payload_reader = payload. byte_stream ( ) . await ?. into_async_read ( ) ;
7983
8084 let mut storage_writer = self
8185 . op
8286 . writer_with ( & path)
87+ . chunk ( self . multipart_policy . part_num_bytes ( payload. len ( ) ) as usize )
8388 . await ?
8489 . into_futures_async_write ( )
8590 . compat_write ( ) ;
0 commit comments