@ -744,6 +744,69 @@ Status DBImpl::ContinueBackgroundWork() {
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
void DBImpl : : NotifyOnCompactionBegin ( ColumnFamilyData * cfd ,
Compaction * c , const Status & st ,
const CompactionJobStats & job_stats ,
int job_id ) {
# ifndef ROCKSDB_LITE
if ( immutable_db_options_ . listeners . empty ( ) ) {
return ;
}
mutex_ . AssertHeld ( ) ;
if ( shutting_down_ . load ( std : : memory_order_acquire ) ) {
return ;
}
Version * current = cfd - > current ( ) ;
current - > Ref ( ) ;
// release lock while notifying events
mutex_ . Unlock ( ) ;
TEST_SYNC_POINT ( " DBImpl::NotifyOnCompactionBegin::UnlockMutex " ) ;
{
CompactionJobInfo info ;
info . cf_name = cfd - > GetName ( ) ;
info . status = st ;
info . thread_id = env_ - > GetThreadID ( ) ;
info . job_id = job_id ;
info . base_input_level = c - > start_level ( ) ;
info . output_level = c - > output_level ( ) ;
info . stats = job_stats ;
info . table_properties = c - > GetOutputTableProperties ( ) ;
info . compaction_reason = c - > compaction_reason ( ) ;
info . compression = c - > output_compression ( ) ;
for ( size_t i = 0 ; i < c - > num_input_levels ( ) ; + + i ) {
for ( const auto fmd : * c - > inputs ( i ) ) {
auto fn = TableFileName ( c - > immutable_cf_options ( ) - > cf_paths ,
fmd - > fd . GetNumber ( ) , fmd - > fd . GetPathId ( ) ) ;
info . input_files . push_back ( fn ) ;
if ( info . table_properties . count ( fn ) = = 0 ) {
std : : shared_ptr < const TableProperties > tp ;
auto s = current - > GetTableProperties ( & tp , fmd , & fn ) ;
if ( s . ok ( ) ) {
info . table_properties [ fn ] = tp ;
}
}
}
}
for ( const auto newf : c - > edit ( ) - > GetNewFiles ( ) ) {
info . output_files . push_back ( TableFileName (
c - > immutable_cf_options ( ) - > cf_paths , newf . second . fd . GetNumber ( ) ,
newf . second . fd . GetPathId ( ) ) ) ;
}
for ( auto listener : immutable_db_options_ . listeners ) {
listener - > OnCompactionBegin ( this , info ) ;
}
}
mutex_ . Lock ( ) ;
current - > Unref ( ) ;
# else
( void ) cfd ;
( void ) c ;
( void ) st ;
( void ) job_stats ;
( void ) job_id ;
# endif // ROCKSDB_LITE
}
void DBImpl : : NotifyOnCompactionCompleted (
void DBImpl : : NotifyOnCompactionCompleted (
ColumnFamilyData * cfd , Compaction * c , const Status & st ,
ColumnFamilyData * cfd , Compaction * c , const Status & st ,
const CompactionJobStats & compaction_job_stats , const int job_id ) {
const CompactionJobStats & compaction_job_stats , const int job_id ) {
@ -1945,6 +2008,9 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
compaction_job_stats . num_input_files = c - > num_input_files ( 0 ) ;
compaction_job_stats . num_input_files = c - > num_input_files ( 0 ) ;
NotifyOnCompactionBegin ( c - > column_family_data ( ) , c . get ( ) , status ,
compaction_job_stats , job_context - > job_id ) ;
for ( const auto & f : * c - > inputs ( 0 ) ) {
for ( const auto & f : * c - > inputs ( 0 ) ) {
c - > edit ( ) - > DeleteFile ( c - > level ( ) , f - > fd . GetNumber ( ) ) ;
c - > edit ( ) - > DeleteFile ( c - > level ( ) , f - > fd . GetNumber ( ) ) ;
}
}
@ -1969,6 +2035,9 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
compaction_job_stats . num_input_files = c - > num_input_files ( 0 ) ;
compaction_job_stats . num_input_files = c - > num_input_files ( 0 ) ;
NotifyOnCompactionBegin ( c - > column_family_data ( ) , c . get ( ) , status ,
compaction_job_stats , job_context - > job_id ) ;
// Move files to next level
// Move files to next level
int32_t moved_files = 0 ;
int32_t moved_files = 0 ;
int64_t moved_bytes = 0 ;
int64_t moved_bytes = 0 ;
@ -2068,6 +2137,9 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
& compaction_job_stats ) ;
& compaction_job_stats ) ;
compaction_job . Prepare ( ) ;
compaction_job . Prepare ( ) ;
NotifyOnCompactionBegin ( c - > column_family_data ( ) , c . get ( ) , status ,
compaction_job_stats , job_context - > job_id ) ;
mutex_ . Unlock ( ) ;
mutex_ . Unlock ( ) ;
compaction_job . Run ( ) ;
compaction_job . Run ( ) ;
TEST_SYNC_POINT ( " DBImpl::BackgroundCompaction:NonTrivial:AfterRun " ) ;
TEST_SYNC_POINT ( " DBImpl::BackgroundCompaction:NonTrivial:AfterRun " ) ;