@@ -125,6 +125,7 @@ pub enum Notification {
125125 Reconstruction ,
126126 PruneBlobs ( Epoch ) ,
127127 ManualFinalization ( ManualFinalizationNotification ) ,
128+ ManualCompaction ,
128129}
129130
130131pub struct ManualFinalizationNotification {
@@ -198,6 +199,14 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
198199 Ok ( ( ) )
199200 }
200201
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+
201210 pub fn process_manual_finalization ( & self , notif : ManualFinalizationNotification ) {
202211 if let Some ( Notification :: ManualFinalization ( notif) ) =
203212 self . send_background_notification ( Notification :: ManualFinalization ( notif) )
@@ -445,6 +454,15 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
445454 debug ! ( log, "Database consolidation complete" ) ;
446455 }
447456
457+ fn run_manual_compaction ( db : Arc < HotColdDB < E , Hot , Cold > > , log : & Logger ) {
458+ debug ! ( log, "Running manual compaction" ) ;
459+ if let Err ( e) = db. compact ( ) {
460+ warn ! ( log, "Database compaction failed" ; "error" => format!( "{:?}" , e) ) ;
461+ } else {
462+ debug ! ( log, "Manual compaction completed" ) ;
463+ }
464+ }
465+
448466 /// Spawn a new child thread to run the migration process.
449467 ///
450468 /// Return a channel handle for sending requests to the thread.
@@ -459,17 +477,20 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
459477 let mut reconstruction_notif = None ;
460478 let mut finalization_notif = None ;
461479 let mut manual_finalization_notif = None ;
480+ let mut manual_compaction_notif = None ;
462481 let mut prune_blobs_notif = None ;
463482 match notif {
464483 Notification :: Reconstruction => reconstruction_notif = Some ( notif) ,
465484 Notification :: Finalization ( fin) => finalization_notif = Some ( fin) ,
466485 Notification :: ManualFinalization ( fin) => manual_finalization_notif = Some ( fin) ,
467486 Notification :: PruneBlobs ( dab) => prune_blobs_notif = Some ( dab) ,
487+ Notification :: ManualCompaction => manual_compaction_notif = Some ( notif) ,
468488 }
469489 // Read the rest of the messages in the channel, taking the best of each type.
470490 for notif in rx. try_iter ( ) {
471491 match notif {
472492 Notification :: Reconstruction => reconstruction_notif = Some ( notif) ,
493+ Notification :: ManualCompaction => manual_compaction_notif = Some ( notif) ,
473494 Notification :: ManualFinalization ( fin) => {
474495 if let Some ( current) = manual_finalization_notif. as_mut ( ) {
475496 if fin. checkpoint . epoch > current. checkpoint . epoch {
@@ -510,6 +531,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
510531 if reconstruction_notif. is_some ( ) {
511532 Self :: run_reconstruction ( db. clone ( ) , Some ( inner_tx. clone ( ) ) , & log) ;
512533 }
534+ if manual_compaction_notif. is_some ( ) {
535+ Self :: run_manual_compaction ( db. clone ( ) , & log) ;
536+ }
513537 }
514538 } ) ;
515539 ( tx, thread)
0 commit comments