@@ -78,6 +78,9 @@ pub struct KeyspaceInner {
78
78
/// True if fsync failed
79
79
pub ( crate ) is_poisoned : Arc < AtomicBool > ,
80
80
81
+ /// Active compaction conter
82
+ pub ( crate ) active_compaction_count : Arc < AtomicUsize > ,
83
+
81
84
#[ doc( hidden) ]
82
85
pub snapshot_tracker : SnapshotTracker ,
83
86
}
@@ -194,6 +197,14 @@ impl Keyspace {
194
197
self . write_buffer_manager . get ( )
195
198
}
196
199
200
+ /// Returns the number of active compactions currently running.
201
+ #[ doc( hidden) ]
202
+ #[ must_use]
203
+ pub fn active_compactions ( & self ) -> usize {
204
+ self . active_compaction_count
205
+ . load ( std:: sync:: atomic:: Ordering :: Relaxed )
206
+ }
207
+
197
208
/// Returns the amount of journals on disk.
198
209
///
199
210
/// # Examples
@@ -580,6 +591,7 @@ impl Keyspace {
580
591
write_buffer_manager : WriteBufferManager :: default ( ) ,
581
592
is_poisoned : Arc :: default ( ) ,
582
593
snapshot_tracker : SnapshotTracker :: default ( ) ,
594
+ active_compaction_count : Arc :: default ( ) ,
583
595
} ;
584
596
585
597
let keyspace = Self ( Arc :: new ( inner) ) ;
@@ -713,6 +725,7 @@ impl Keyspace {
713
725
write_buffer_manager : WriteBufferManager :: default ( ) ,
714
726
is_poisoned : Arc :: default ( ) ,
715
727
snapshot_tracker : SnapshotTracker :: default ( ) ,
728
+ active_compaction_count : Arc :: default ( ) ,
716
729
} ;
717
730
718
731
// NOTE: Lastly, fsync .fjall marker, which contains the version
@@ -792,6 +805,7 @@ impl Keyspace {
792
805
let stop_signal = self . stop_signal . clone ( ) ;
793
806
let thread_counter = self . active_background_threads . clone ( ) ;
794
807
let snapshot_tracker = self . snapshot_tracker . clone ( ) ;
808
+ let compaction_counter = self . active_compaction_count . clone ( ) ;
795
809
796
810
thread_counter. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
797
811
@@ -802,7 +816,11 @@ impl Keyspace {
802
816
log:: trace!( "compaction: waiting for work" ) ;
803
817
compaction_manager. wait_for ( ) ;
804
818
805
- crate :: compaction:: worker:: run ( & compaction_manager, & snapshot_tracker) ;
819
+ crate :: compaction:: worker:: run (
820
+ & compaction_manager,
821
+ & snapshot_tracker,
822
+ & compaction_counter,
823
+ ) ;
806
824
}
807
825
808
826
log:: trace!( "compaction thread: exiting because keyspace is dropping" ) ;
0 commit comments