@@ -32,6 +32,8 @@ use crate::object_writer::WriteResult;
3232use crate :: traits:: { ByteStream , Reader , Writer } ;
3333use crate :: utils:: tracking_store:: IOTracker ;
3434
35+ mod admitted_read;
36+
3537/// Convert an [`object_store::path::Path`] to a [`std::path::Path`].
3638pub fn to_local_path ( path : & Path ) -> String {
3739 if cfg ! ( windows) {
@@ -241,6 +243,9 @@ pub struct LocalObjectReader {
241243 /// File handler.
242244 file : Arc < File > ,
243245
246+ /// Lazy coordination for owned reads; ordinary reads bypass it.
247+ admitted_read : admitted_read:: ReadGate ,
248+
244249 /// Fie path.
245250 path : Path ,
246251
@@ -303,6 +308,7 @@ impl LocalObjectReader {
303308 let size = OnceCell :: new_with ( known_size) ;
304309 Ok ( Box :: new ( Self {
305310 file : Arc :: new ( file) ,
311+ admitted_read : Default :: default ( ) ,
306312 block_size,
307313 size,
308314 path,
@@ -398,14 +404,16 @@ impl Reader for LocalObjectReader {
398404 let metrics = io_tracker. begin_io ( "get" ) ;
399405 // The blocking operation owns the reservation. Dropping the async
400406 // waiter must not refund memory while the read still writes into it.
401- let result = join_local_io ( tokio:: task:: spawn_blocking ( move || {
402- #[ cfg( unix) ]
403- file. read_exact_at ( output. as_mut ( ) , range. start as u64 ) ?;
404- #[ cfg( windows) ]
405- read_exact_at ( file, output. as_mut ( ) , range. start as u64 ) ?;
406- Ok ( output)
407- } ) )
408- . await ;
407+ let result = self
408+ . admitted_read
409+ . run ( file, move |file| {
410+ #[ cfg( unix) ]
411+ file. read_exact_at ( output. as_mut ( ) , range. start as u64 ) ?;
412+ #[ cfg( windows) ]
413+ read_exact_at ( file, output. as_mut ( ) , range. start as u64 ) ?;
414+ Ok ( output)
415+ } )
416+ . await ;
409417 metrics. record ( & result, bytes) ;
410418 if result. is_ok ( ) {
411419 io_tracker. record_read ( "get_range_into" , path, bytes, Some ( range_u64) ) ;
@@ -434,27 +442,30 @@ impl Reader for LocalObjectReader {
434442 }
435443 // One blocking dispatch, still one positional read and metric per
436444 // range. The closure owns every buffer even if its waiter is dropped.
437- Ok ( join_local_io ( tokio:: task:: spawn_blocking ( move || {
438- let mut outputs = Vec :: with_capacity ( requests. len ( ) ) ;
439- for ( range, mut output) in requests {
440- let metrics = io_tracker. begin_io ( "get" ) ;
441- #[ cfg( unix) ]
442- let result = file. read_exact_at ( output. as_mut ( ) , range. start as u64 ) ;
443- #[ cfg( windows) ]
444- let result = read_exact_at ( file. clone ( ) , output. as_mut ( ) , range. start as u64 ) ;
445- metrics. record ( & result, range. len ( ) as u64 ) ;
446- result?;
447- io_tracker. record_read (
448- "get_range_into" ,
449- path. clone ( ) ,
450- range. len ( ) as u64 ,
451- Some ( range. start as u64 ..range. end as u64 ) ,
452- ) ;
453- outputs. push ( output) ;
454- }
455- Ok ( outputs)
456- } ) )
457- . await ?)
445+ Ok ( self
446+ . admitted_read
447+ . run ( file, move |file| {
448+ let mut outputs = Vec :: with_capacity ( requests. len ( ) ) ;
449+ for ( range, mut output) in requests {
450+ let metrics = io_tracker. begin_io ( "get" ) ;
451+ #[ cfg( unix) ]
452+ let result = file. read_exact_at ( output. as_mut ( ) , range. start as u64 ) ;
453+ #[ cfg( windows) ]
454+ let result =
455+ read_exact_at ( file. clone ( ) , output. as_mut ( ) , range. start as u64 ) ;
456+ metrics. record ( & result, range. len ( ) as u64 ) ;
457+ result?;
458+ io_tracker. record_read (
459+ "get_range_into" ,
460+ path. clone ( ) ,
461+ range. len ( ) as u64 ,
462+ Some ( range. start as u64 ..range. end as u64 ) ,
463+ ) ;
464+ outputs. push ( output) ;
465+ }
466+ Ok ( outputs)
467+ } )
468+ . await ?)
458469 } )
459470 }
460471
0 commit comments