@@ -90,6 +90,8 @@ pub trait ExtendedObjectStore: ObjectStore {
90
90
/// Get the number of bytes read in requests.
91
91
fn get_bytes_read ( & self ) -> Option < usize > ;
92
92
93
+ fn set_total_predicted ( & mut self , prediction : Option < usize > ) ;
94
+
93
95
/// Trait upcasting.
94
96
fn as_object_store ( self : Arc < Self > ) -> Arc < dyn ObjectStore > ;
95
97
}
@@ -196,6 +198,7 @@ pub async fn default_s3_config() -> color_eyre::Result<AmazonS3Builder> {
196
198
pub struct LoggingObjectStore {
197
199
store : Arc < dyn ObjectStore > ,
198
200
get_count : Mutex < usize > ,
201
+ total_predicted : Option < usize > ,
199
202
get_bytes_read : Mutex < usize > ,
200
203
capacity : Mutex < usize > ,
201
204
}
@@ -205,6 +208,7 @@ impl LoggingObjectStore {
205
208
Self {
206
209
store : inner,
207
210
get_count : Mutex :: new ( 0 ) ,
211
+ total_predicted : None ,
208
212
get_bytes_read : Mutex :: new ( 0 ) ,
209
213
capacity : Mutex :: new ( MULTIPART_BUF_SIZE ) ,
210
214
}
@@ -277,6 +281,10 @@ impl ObjectStore for LoggingObjectStore {
277
281
* self . get_bytes_read . lock ( ) . unwrap ( ) += range. len ( ) ;
278
282
}
279
283
* self . get_count . lock ( ) . unwrap ( ) += 1 ;
284
+ if let Some ( total) = self . total_predicted {
285
+ let percentComplete: <usize as Div < f64 > >:: Output =
286
+ * self . get_count . lock ( ) . unwrap ( ) / ( total as f64 ) ;
287
+ }
280
288
self . store . get_opts ( location, options)
281
289
}
282
290
@@ -432,6 +440,12 @@ impl ExtendedObjectStore for LoggingObjectStore {
432
440
fn as_object_store ( self : Arc < Self > ) -> Arc < dyn ObjectStore > {
433
441
self
434
442
}
443
+
444
+ fn set_total_predicted ( & mut self , prediction : Option < usize > ) {
445
+ if let Some ( value) = prediction {
446
+ self . total_predicted = Some ( value) ;
447
+ }
448
+ }
435
449
}
436
450
437
451
#[ derive( Debug ) ]
0 commit comments