@@ -125,6 +125,7 @@ pub enum Notification {
125
125
Reconstruction ,
126
126
PruneBlobs ( Epoch ) ,
127
127
ManualFinalization ( ManualFinalizationNotification ) ,
128
+ ManualCompaction ,
128
129
}
129
130
130
131
pub struct ManualFinalizationNotification {
@@ -198,6 +199,14 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
198
199
Ok ( ( ) )
199
200
}
200
201
202
+ pub fn process_manual_compaction ( & self ) {
203
+ if let Some ( Notification :: ManualCompaction ) =
204
+ self . send_background_notification ( Notification :: ManualCompaction )
205
+ {
206
+ Self :: run_manual_compaction ( self . db . clone ( ) , & self . log ) ;
207
+ }
208
+ }
209
+
201
210
pub fn process_manual_finalization ( & self , notif : ManualFinalizationNotification ) {
202
211
if let Some ( Notification :: ManualFinalization ( notif) ) =
203
212
self . send_background_notification ( Notification :: ManualFinalization ( notif) )
@@ -446,6 +455,15 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
446
455
debug ! ( log, "Database consolidation complete" ) ;
447
456
}
448
457
458
+ fn run_manual_compaction ( db : Arc < HotColdDB < E , Hot , Cold > > , log : & Logger ) {
459
+ debug ! ( log, "Running manual compaction" ) ;
460
+ if let Err ( e) = db. compact ( ) {
461
+ warn ! ( log, "Database compaction failed" ; "error" => format!( "{:?}" , e) ) ;
462
+ } else {
463
+ debug ! ( log, "Manual compaction completed" ) ;
464
+ }
465
+ }
466
+
449
467
/// Spawn a new child thread to run the migration process.
450
468
///
451
469
/// Return a channel handle for sending requests to the thread.
@@ -460,17 +478,20 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
460
478
let mut reconstruction_notif = None ;
461
479
let mut finalization_notif = None ;
462
480
let mut manual_finalization_notif = None ;
481
+ let mut manual_compaction_notif = None ;
463
482
let mut prune_blobs_notif = None ;
464
483
match notif {
465
484
Notification :: Reconstruction => reconstruction_notif = Some ( notif) ,
466
485
Notification :: Finalization ( fin) => finalization_notif = Some ( fin) ,
467
486
Notification :: ManualFinalization ( fin) => manual_finalization_notif = Some ( fin) ,
468
487
Notification :: PruneBlobs ( dab) => prune_blobs_notif = Some ( dab) ,
488
+ Notification :: ManualCompaction => manual_compaction_notif = Some ( notif) ,
469
489
}
470
490
// Read the rest of the messages in the channel, taking the best of each type.
471
491
for notif in rx. try_iter ( ) {
472
492
match notif {
473
493
Notification :: Reconstruction => reconstruction_notif = Some ( notif) ,
494
+ Notification :: ManualCompaction => manual_compaction_notif = Some ( notif) ,
474
495
Notification :: ManualFinalization ( fin) => {
475
496
if let Some ( current) = manual_finalization_notif. as_mut ( ) {
476
497
if fin. checkpoint . epoch > current. checkpoint . epoch {
@@ -511,6 +532,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
511
532
if reconstruction_notif. is_some ( ) {
512
533
Self :: run_reconstruction ( db. clone ( ) , Some ( inner_tx. clone ( ) ) , & log) ;
513
534
}
535
+ if manual_compaction_notif. is_some ( ) {
536
+ Self :: run_manual_compaction ( db. clone ( ) , & log) ;
537
+ }
514
538
}
515
539
} ) ;
516
540
( tx, thread)
0 commit comments