@@ -512,9 +512,9 @@ impl ImportSource {
512
512
}
513
513
514
514
/// Use BaoFileHandle as the entry type for the map.
515
- pub type Entry = BaoFileHandle ;
515
+ pub type Entry < T > = BaoFileHandle < T > ;
516
516
517
- impl super :: MapEntry for Entry {
517
+ impl < T > super :: MapEntry for Entry < T > {
518
518
fn hash ( & self ) -> Hash {
519
519
self . hash ( )
520
520
}
@@ -530,15 +530,15 @@ impl super::MapEntry for Entry {
530
530
}
531
531
532
532
async fn outboard ( & self ) -> io:: Result < impl Outboard > {
533
- self . outboard ( )
533
+ BaoFileHandle :: outboard ( self )
534
534
}
535
535
536
536
async fn data_reader ( & self ) -> io:: Result < impl AsyncSliceReader > {
537
537
Ok ( self . data_reader ( ) )
538
538
}
539
539
}
540
540
541
- impl super :: MapEntryMut for Entry {
541
+ impl < T > super :: MapEntryMut for Entry < T > {
542
542
async fn batch_writer ( & self ) -> io:: Result < impl BaoBatchWriter > {
543
543
Ok ( self . writer ( ) )
544
544
}
@@ -572,12 +572,12 @@ pub(crate) struct Export {
572
572
}
573
573
574
574
#[ derive( derive_more:: Debug ) ]
575
- pub ( crate ) enum ActorMessage {
575
+ pub ( crate ) enum ActorMessage < T > {
576
576
// Query method: get a file handle for a hash, if it exists.
577
577
// This will produce a file handle even for entries that are not yet in redb at all.
578
578
Get {
579
579
hash : Hash ,
580
- tx : oneshot:: Sender < ActorResult < Option < BaoFileHandle > > > ,
580
+ tx : oneshot:: Sender < ActorResult < Option < BaoFileHandle < T > > > > ,
581
581
} ,
582
582
/// Query method: get the rough entry status for a hash. Just complete, partial or not found.
583
583
EntryStatus {
@@ -609,15 +609,15 @@ pub(crate) enum ActorMessage {
609
609
/// will be created, but not yet written to redb.
610
610
GetOrCreate {
611
611
hash : Hash ,
612
- tx : oneshot:: Sender < ActorResult < BaoFileHandle > > ,
612
+ tx : oneshot:: Sender < ActorResult < BaoFileHandle < T > > > ,
613
613
} ,
614
614
/// Modification method: inline size was exceeded for a partial entry.
615
615
/// If the entry is complete, this is a no-op. If the entry is partial and in
616
616
/// memory, it will be written to a file and created in redb.
617
617
OnMemSizeExceeded { hash : Hash } ,
618
618
/// Modification method: marks a partial entry as complete.
619
619
/// Calling this on a complete entry is a no-op.
620
- OnComplete { handle : BaoFileHandle } ,
620
+ OnComplete { handle : BaoFileHandle < T > } ,
621
621
/// Modification method: import data into a redb store
622
622
///
623
623
/// At this point the size, hash and outboard must already be known.
@@ -718,7 +718,7 @@ pub(crate) enum ActorMessage {
718
718
Shutdown { tx : Option < oneshot:: Sender < ( ) > > } ,
719
719
}
720
720
721
- impl ActorMessage {
721
+ impl < T > ActorMessage < T > {
722
722
fn category ( & self ) -> MessageCategory {
723
723
match self {
724
724
Self :: Get { .. }
@@ -810,8 +810,8 @@ impl Store {
810
810
}
811
811
812
812
#[ derive( Debug ) ]
813
- struct StoreInner < T > {
814
- tx : async_channel:: Sender < ActorMessage > ,
813
+ struct StoreInner < T : Persistence > {
814
+ tx : async_channel:: Sender < ActorMessage < T :: File > > ,
815
815
temp : Arc < RwLock < TempCounterMap > > ,
816
816
handle : Option < std:: thread:: JoinHandle < ( ) > > ,
817
817
path_options : Arc < PathOptions > ,
@@ -1019,7 +1019,7 @@ where
1019
1019
Ok ( rx. recv ( ) ??)
1020
1020
}
1021
1021
1022
- async fn complete ( & self , entry : Entry ) -> OuterResult < ( ) > {
1022
+ async fn complete ( & self , entry : Entry < T :: File > ) -> OuterResult < ( ) > {
1023
1023
self . tx
1024
1024
. send ( ActorMessage :: OnComplete { handle : entry } )
1025
1025
. await ?;
@@ -1245,11 +1245,11 @@ impl<T> Drop for StoreInner<T> {
1245
1245
}
1246
1246
}
1247
1247
1248
- struct ActorState < T > {
1249
- handles : BTreeMap < Hash , BaoFileHandleWeak > ,
1248
+ struct ActorState < T : Persistence > {
1249
+ handles : BTreeMap < Hash , BaoFileHandleWeak < T :: File > > ,
1250
1250
protected : BTreeSet < Hash > ,
1251
1251
temp : Arc < RwLock < TempCounterMap > > ,
1252
- msgs_rx : async_channel:: Receiver < ActorMessage > ,
1252
+ msgs_rx : async_channel:: Receiver < ActorMessage < T :: File > > ,
1253
1253
create_options : Arc < BaoFileConfig > ,
1254
1254
options : Options ,
1255
1255
rt : tokio:: runtime:: Handle ,
@@ -1320,8 +1320,8 @@ pub(crate) enum OuterError {
1320
1320
JoinTask ( #[ from] tokio:: task:: JoinError ) ,
1321
1321
}
1322
1322
1323
- impl From < async_channel:: SendError < ActorMessage > > for OuterError {
1324
- fn from ( _e : async_channel:: SendError < ActorMessage > ) -> Self {
1323
+ impl < T > From < async_channel:: SendError < ActorMessage < T > > > for OuterError {
1324
+ fn from ( _e : async_channel:: SendError < ActorMessage < T > > ) -> Self {
1325
1325
OuterError :: Send
1326
1326
}
1327
1327
}
@@ -1613,14 +1613,17 @@ pub(super) async fn gc_sweep_task(
1613
1613
Ok ( ( ) )
1614
1614
}
1615
1615
1616
- impl < T > Actor < T > {
1616
+ impl < T > Actor < T >
1617
+ where
1618
+ T : Persistence ,
1619
+ {
1617
1620
fn new_with_backend (
1618
1621
path : & Path ,
1619
1622
options : Options ,
1620
1623
temp : Arc < RwLock < TempCounterMap > > ,
1621
1624
rt : tokio:: runtime:: Handle ,
1622
1625
fs : T ,
1623
- ) -> ActorResult < ( Self , async_channel:: Sender < ActorMessage > ) > {
1626
+ ) -> ActorResult < ( Self , async_channel:: Sender < ActorMessage < T :: File > > ) > {
1624
1627
let db = match redb:: Database :: create ( path) {
1625
1628
Ok ( db) => db,
1626
1629
Err ( DatabaseError :: UpgradeRequired ( 1 ) ) => {
@@ -1787,7 +1790,7 @@ where
1787
1790
& mut self ,
1788
1791
tables : & impl ReadableTables ,
1789
1792
hash : Hash ,
1790
- ) -> ActorResult < Option < BaoFileHandle > > {
1793
+ ) -> ActorResult < Option < BaoFileHandle < T :: File > > > {
1791
1794
if let Some ( handle) = self . handles . get ( & hash) . and_then ( |weak| weak. upgrade ( ) ) {
1792
1795
return Ok ( Some ( handle) ) ;
1793
1796
}
@@ -2033,7 +2036,7 @@ where
2033
2036
& mut self ,
2034
2037
tables : & impl ReadableTables ,
2035
2038
hash : Hash ,
2036
- ) -> ActorResult < BaoFileHandle > {
2039
+ ) -> ActorResult < BaoFileHandle < T :: File > > {
2037
2040
self . protected . insert ( hash) ;
2038
2041
if let Some ( handle) = self . handles . get ( & hash) . and_then ( |x| x. upgrade ( ) ) {
2039
2042
return Ok ( handle) ;
@@ -2344,7 +2347,11 @@ where
2344
2347
Ok ( ( ) )
2345
2348
}
2346
2349
2347
- fn on_complete ( & mut self , tables : & mut Tables , entry : BaoFileHandle ) -> ActorResult < ( ) > {
2350
+ fn on_complete (
2351
+ & mut self ,
2352
+ tables : & mut Tables ,
2353
+ entry : BaoFileHandle < T :: File > ,
2354
+ ) -> ActorResult < ( ) > {
2348
2355
let hash = entry. hash ( ) ;
2349
2356
let mut info = None ;
2350
2357
tracing:: trace!( "on_complete({})" , hash. to_hex( ) ) ;
@@ -2414,7 +2421,11 @@ where
2414
2421
Ok ( ( ) )
2415
2422
}
2416
2423
2417
- fn handle_toplevel ( & mut self , db : & redb:: Database , msg : ActorMessage ) -> ActorResult < ( ) > {
2424
+ fn handle_toplevel (
2425
+ & mut self ,
2426
+ db : & redb:: Database ,
2427
+ msg : ActorMessage < T :: File > ,
2428
+ ) -> ActorResult < ( ) > {
2418
2429
match msg {
2419
2430
ActorMessage :: UpdateInlineOptions {
2420
2431
inline_options,
@@ -2448,8 +2459,8 @@ where
2448
2459
fn handle_readonly (
2449
2460
& mut self ,
2450
2461
tables : & impl ReadableTables ,
2451
- msg : ActorMessage ,
2452
- ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage > > {
2462
+ msg : ActorMessage < T :: File > ,
2463
+ ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage < T :: File > > > {
2453
2464
match msg {
2454
2465
ActorMessage :: Get { hash, tx } => {
2455
2466
let res = self . get ( tables, hash) ;
@@ -2495,8 +2506,8 @@ where
2495
2506
fn handle_readwrite (
2496
2507
& mut self ,
2497
2508
tables : & mut Tables ,
2498
- msg : ActorMessage ,
2499
- ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage > > {
2509
+ msg : ActorMessage < T :: File > ,
2510
+ ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage < T :: File > > > {
2500
2511
match msg {
2501
2512
ActorMessage :: Import { cmd, tx } => {
2502
2513
let res = self . import ( tables, cmd) ;
0 commit comments