1- use crate :: { CResult , Config , NotifyGuard , SQ , clients , dyn_connect , static_config, Request , util:: cstr_to_path, Context , RawResponse , ResponseGuard } ;
1+ use crate :: { CResult , Client , RawConfig , NotifyGuard , SQ , static_config, Request , util:: cstr_to_path, Context , RawResponse , ResponseGuard } ;
22
33use object_store:: { path:: Path , ObjectStore } ;
44
55use anyhow:: anyhow;
66use std:: ffi:: { c_char, c_void} ;
77use futures_util:: StreamExt ;
88use tokio:: io:: AsyncWriteExt ;
9- use std:: sync:: Arc ;
109
1110// The type used to give Julia the result of an async request. It will be allocated
1211// by Julia as part of the request and filled in by Rust.
@@ -43,15 +42,15 @@ impl RawResponse for Response {
4342 }
4443}
4544
46- async fn multipart_get ( slice : & mut [ u8 ] , path : & Path , client : & dyn ObjectStore ) -> anyhow:: Result < usize > {
47- let result = client. head ( & path) . await ?;
45+ async fn multipart_get ( slice : & mut [ u8 ] , path : & Path , client : & Client ) -> anyhow:: Result < usize > {
46+ let result = client. store . head ( & path) . await ?;
4847 if result. size > slice. len ( ) {
4948 return Err ( anyhow ! ( "Supplied buffer was too small" ) ) ;
5049 }
5150
5251 let part_ranges = crate :: util:: size_to_ranges ( result. size ) ;
5352
54- let result_vec = client. get_ranges ( & path, & part_ranges) . await ?;
53+ let result_vec = client. store . get_ranges ( & path, & part_ranges) . await ?;
5554 let mut accum: usize = 0 ;
5655 for i in 0 ..result_vec. len ( ) {
5756 slice[ accum..accum + result_vec[ i] . len ( ) ] . copy_from_slice ( & result_vec[ i] ) ;
@@ -61,9 +60,9 @@ async fn multipart_get(slice: &mut [u8], path: &Path, client: &dyn ObjectStore)
6160 return Ok ( accum) ;
6261}
6362
64- async fn multipart_put ( slice : & [ u8 ] , path : & Path , client : Arc < dyn ObjectStore > ) -> anyhow:: Result < ( ) > {
63+ async fn multipart_put ( slice : & [ u8 ] , path : & Path , client : Client ) -> anyhow:: Result < ( ) > {
6564 let mut writer = object_store:: buffered:: BufWriter :: with_capacity (
66- client,
65+ client. store ,
6766 path. clone ( ) ,
6867 10 * 1024 * 1024
6968 )
@@ -88,19 +87,15 @@ async fn multipart_put(slice: &[u8], path: &Path, client: Arc<dyn ObjectStore>)
8887 } ;
8988}
9089
91- pub ( crate ) async fn handle_get ( slice : & mut [ u8 ] , path : & Path , config : & Config ) -> anyhow:: Result < usize > {
92- let ( client, _) = clients ( )
93- . try_get_with ( config. get_hash ( ) , dyn_connect ( config) ) . await
94- . map_err ( |e| anyhow ! ( e) ) ?;
95-
90+ pub ( crate ) async fn handle_get ( client : Client , slice : & mut [ u8 ] , path : & Path ) -> anyhow:: Result < usize > {
9691 // Multipart Get
9792 if slice. len ( ) > static_config ( ) . multipart_get_threshold as usize {
9893 let accum = multipart_get ( slice, path, & client) . await ?;
9994 return Ok ( accum) ;
10095 }
10196
10297 // Single part Get
103- let body = client. get ( path) . await ?;
98+ let body = client. store . get ( path) . await ?;
10499 let mut batch_stream = body. into_stream ( ) . chunks ( 8 ) ;
105100
106101 let mut received_bytes = 0 ;
@@ -129,27 +124,19 @@ pub(crate) async fn handle_get(slice: &mut [u8], path: &Path, config: &Config) -
129124 Ok ( received_bytes)
130125}
131126
132- pub ( crate ) async fn handle_put ( slice : & ' static [ u8 ] , path : & Path , config : & Config ) -> anyhow:: Result < usize > {
133- let ( client, _) = clients ( )
134- . try_get_with ( config. get_hash ( ) , dyn_connect ( config) ) . await
135- . map_err ( |e| anyhow ! ( e) ) ?;
136-
127+ pub ( crate ) async fn handle_put ( client : Client , slice : & ' static [ u8 ] , path : & Path ) -> anyhow:: Result < usize > {
137128 let len = slice. len ( ) ;
138129 if len < static_config ( ) . multipart_put_threshold as usize {
139- let _ = client. put ( path, slice. into ( ) ) . await ?;
130+ let _ = client. store . put ( path, slice. into ( ) ) . await ?;
140131 } else {
141132 let _ = multipart_put ( slice, path, client) . await ?;
142133 }
143134
144135 Ok ( len)
145136}
146137
147- pub ( crate ) async fn handle_delete ( path : & Path , config : & Config ) -> anyhow:: Result < usize > {
148- let ( client, _) = clients ( )
149- . try_get_with ( config. get_hash ( ) , dyn_connect ( config) ) . await
150- . map_err ( |e| anyhow ! ( e) ) ?;
151-
152- client. delete ( path) . await ?;
138+ pub ( crate ) async fn handle_delete ( client : Client , path : & Path ) -> anyhow:: Result < usize > {
139+ client. store . delete ( path) . await ?;
153140
154141 Ok ( 0 )
155142}
@@ -159,7 +146,7 @@ pub extern "C" fn get(
159146 path : * const c_char ,
160147 buffer : * mut u8 ,
161148 size : usize ,
162- config : * const Config ,
149+ config : * const RawConfig ,
163150 response : * mut Response ,
164151 handle : * const c_void
165152) -> CResult {
@@ -195,7 +182,7 @@ pub extern "C" fn put(
195182 path : * const c_char ,
196183 buffer : * const u8 ,
197184 size : usize ,
198- config : * const Config ,
185+ config : * const RawConfig ,
199186 response : * mut Response ,
200187 handle : * const c_void
201188) -> CResult {
@@ -229,7 +216,7 @@ pub extern "C" fn put(
229216#[ no_mangle]
230217pub extern "C" fn delete (
231218 path : * const c_char ,
232- config : * const Config ,
219+ config : * const RawConfig ,
233220 response : * mut Response ,
234221 handle : * const c_void
235222) -> CResult {
0 commit comments