@@ -335,26 +335,25 @@ impl Default for BaoFileStorage {
335
335
impl PartialMemStorage {
336
336
/// Converts this storage into a complete storage, using the given hash for
337
337
/// path names and the given options for decisions about inlining.
338
- fn into_complete (
339
- self ,
340
- hash : & Hash ,
341
- ctx : & TaskContext ,
342
- ) -> io:: Result < ( CompleteStorage , EntryState < Bytes > ) > {
338
+ fn into_complete ( self , ctx : & HashContext ) -> io:: Result < ( CompleteStorage , EntryState < Bytes > ) > {
339
+ let options = & ctx. global . options ;
340
+ let hash = & ctx. id ;
343
341
let size = self . current_size ( ) ;
344
342
let outboard_size = raw_outboard_size ( size) ;
345
- let ( data, data_location) = if ctx . options . is_inlined_data ( size) {
343
+ let ( data, data_location) = if options. is_inlined_data ( size) {
346
344
let data: Bytes = self . data . to_vec ( ) . into ( ) ;
347
345
( MemOrFile :: Mem ( data. clone ( ) ) , DataLocation :: Inline ( data) )
348
346
} else {
349
- let data_path = ctx . options . path . data_path ( hash) ;
347
+ let data_path = options. path . data_path ( hash) ;
350
348
let mut data_file = create_read_write ( & data_path) ?;
351
349
self . data . persist ( & mut data_file) ?;
352
350
(
353
351
MemOrFile :: File ( FixedSize :: new ( data_file, size) ) ,
354
352
DataLocation :: Owned ( size) ,
355
353
)
356
354
} ;
357
- let ( outboard, outboard_location) = if ctx. options . is_inlined_outboard ( outboard_size) {
355
+ let ( outboard, outboard_location) = if ctx. global . options . is_inlined_outboard ( outboard_size)
356
+ {
358
357
if outboard_size > 0 {
359
358
let outboard: Bytes = self . outboard . to_vec ( ) . into ( ) ;
360
359
(
@@ -365,7 +364,7 @@ impl PartialMemStorage {
365
364
( MemOrFile :: empty ( ) , OutboardLocation :: NotNeeded )
366
365
}
367
366
} else {
368
- let outboard_path = ctx. options . path . outboard_path ( hash) ;
367
+ let outboard_path = ctx. global . options . path . outboard_path ( hash) ;
369
368
let mut outboard_file = create_read_write ( & outboard_path) ?;
370
369
self . outboard . persist ( & mut outboard_file) ?;
371
370
let outboard_location = if outboard_size == 0 {
@@ -411,10 +410,10 @@ impl BaoFileStorage {
411
410
let changes = ms. bitfield . update ( bitfield) ;
412
411
let new = changes. new_state ( ) ;
413
412
if new. complete {
414
- let ( cs, update) = ms. into_complete ( & ctx. id , & ctx . global ) ?;
413
+ let ( cs, update) = ms. into_complete ( ctx) ?;
415
414
( cs. into ( ) , Some ( update) )
416
415
} else {
417
- let fs = ms. persist ( & ctx. global , & ctx . id ) ?;
416
+ let fs = ms. persist ( ctx) ?;
418
417
let update = EntryState :: Partial {
419
418
size : new. validated_size ,
420
419
} ;
@@ -427,7 +426,7 @@ impl BaoFileStorage {
427
426
// a write at the end of a very large file.
428
427
//
429
428
// opt: we should check if we become complete to avoid going from mem to partial to complete
430
- let mut fs = ms. persist ( & ctx. global , & ctx . id ) ?;
429
+ let mut fs = ms. persist ( ctx) ?;
431
430
fs. write_batch ( bitfield. size ( ) , batch) ?;
432
431
let changes = fs. bitfield . update ( bitfield) ;
433
432
let new = changes. new_state ( ) ;
@@ -507,20 +506,17 @@ impl BaoFileStorage {
507
506
pub ( crate ) struct BaoFileHandle ( Arc < watch:: Sender < BaoFileStorage > > ) ;
508
507
509
508
impl BaoFileHandle {
510
- pub fn persist ( & mut self , hash : & Hash , options : & Options ) {
509
+ pub ( super ) fn persist ( & mut self , ctx : & HashContext ) {
511
510
self . send_if_modified ( |guard| {
511
+ let hash = & ctx. id ;
512
512
if Arc :: strong_count ( & self . 0 ) > 1 {
513
513
return false ;
514
514
}
515
515
let BaoFileStorage :: Partial ( fs) = guard. take ( ) else {
516
516
return false ;
517
517
} ;
518
- let path = options. path . bitfield_path ( hash) ;
519
- trace ! (
520
- "writing bitfield for hash {} to {}" ,
521
- hash,
522
- path. display( )
523
- ) ;
518
+ let path = ctx. global . options . path . bitfield_path ( hash) ;
519
+ trace ! ( "writing bitfield for hash {} to {}" , hash, path. display( ) ) ;
524
520
if let Err ( cause) = fs. sync_all ( & path) {
525
521
error ! (
526
522
"failed to write bitfield for {} at {}: {:?}" ,
@@ -695,8 +691,7 @@ impl BaoFileHandle {
695
691
trace ! ( "write_batch bitfield={:?} batch={}" , bitfield, batch. len( ) ) ;
696
692
let mut res = Ok ( None ) ;
697
693
self . send_if_modified ( |state| {
698
- let Ok ( ( state1, update) ) = state. take ( ) . write_batch ( batch, bitfield, ctx)
699
- else {
694
+ let Ok ( ( state1, update) ) = state. take ( ) . write_batch ( batch, bitfield, ctx) else {
700
695
res = Err ( io:: Error :: other ( "write batch failed" ) ) ;
701
696
return false ;
702
697
} ;
@@ -713,9 +708,10 @@ impl BaoFileHandle {
713
708
714
709
impl PartialMemStorage {
715
710
/// Persist the batch to disk.
716
- fn persist ( self , ctx : & TaskContext , hash : & Hash ) -> io:: Result < PartialFileStorage > {
717
- let options = & ctx. options . path ;
718
- ctx. protect . protect (
711
+ fn persist ( self , ctx : & HashContext ) -> io:: Result < PartialFileStorage > {
712
+ let options = & ctx. global . options . path ;
713
+ let hash = & ctx. id ;
714
+ ctx. global . protect . protect (
719
715
* hash,
720
716
[
721
717
BaoFilePart :: Data ,
0 commit comments