@ -1760,7 +1760,7 @@ Status DBImpl::RunManualCompaction(
input_level > = 0 ) ;
input_level > = 0 ) ;
InternalKey begin_storage , end_storage ;
InternalKey begin_storage , end_storage ;
CompactionArg * ca ;
CompactionArg * ca = nullptr ;
bool scheduled = false ;
bool scheduled = false ;
bool manual_conflict = false ;
bool manual_conflict = false ;
@ -1879,6 +1879,16 @@ Status DBImpl::RunManualCompaction(
assert ( ! exclusive | | ! manual_conflict ) ;
assert ( ! exclusive | | ! manual_conflict ) ;
// Running either this or some other manual compaction
// Running either this or some other manual compaction
bg_cv_ . Wait ( ) ;
bg_cv_ . Wait ( ) ;
if ( manual_compaction_paused_ > 0 & & ! manual . done & &
! manual . in_progress ) {
manual . done = true ;
manual . status =
Status : : Incomplete ( Status : : SubCode : : kManualCompactionPaused ) ;
if ( ca & & ca - > prepicked_compaction ) {
ca - > prepicked_compaction - > is_canceled = true ;
}
break ;
}
if ( scheduled & & manual . incomplete = = true ) {
if ( scheduled & & manual . incomplete = = true ) {
assert ( ! manual . in_progress ) ;
assert ( ! manual . in_progress ) ;
scheduled = false ;
scheduled = false ;
@ -1915,6 +1925,7 @@ Status DBImpl::RunManualCompaction(
& DBImpl : : UnscheduleCompactionCallback ) ;
& DBImpl : : UnscheduleCompactionCallback ) ;
}
}
scheduled = true ;
scheduled = true ;
TEST_SYNC_POINT ( " DBImpl::RunManualCompaction:Scheduled " ) ;
}
}
}
}
@ -2840,91 +2851,106 @@ void DBImpl::BackgroundCallFlush(Env::Priority thread_pri) {
void DBImpl : : BackgroundCallCompaction ( PrepickedCompaction * prepicked_compaction ,
void DBImpl : : BackgroundCallCompaction ( PrepickedCompaction * prepicked_compaction ,
Env : : Priority bg_thread_pri ) {
Env : : Priority bg_thread_pri ) {
bool made_progress = false ;
bool made_progress = false ;
JobContext job_context ( next_job_id_ . fetch_add ( 1 ) , true ) ;
TEST_SYNC_POINT ( " BackgroundCallCompaction:0 " ) ;
TEST_SYNC_POINT ( " BackgroundCallCompaction:0 " ) ;
LogBuffer log_buffer ( InfoLogLevel : : INFO_LEVEL ,
LogBuffer log_buffer ( InfoLogLevel : : INFO_LEVEL ,
immutable_db_options_ . info_log . get ( ) ) ;
immutable_db_options_ . info_log . get ( ) ) ;
{
{
InstrumentedMutexLock l ( & mutex_ ) ;
InstrumentedMutexLock l ( & mutex_ ) ;
// This call will unlock/lock the mutex to wait for current running
if ( prepicked_compaction & & prepicked_compaction - > is_canceled ) {
// IngestExternalFile() calls to finish.
assert ( prepicked_compaction - > compaction ) ;
WaitForIngestFile ( ) ;
ROCKS_LOG_BUFFER ( & log_buffer , " [%s] Skip canceled manual compaction job " ,
prepicked_compaction - > compaction - > column_family_data ( )
num_running_compactions_ + + ;
- > GetName ( )
. c_str ( ) ) ;
std : : unique_ptr < std : : list < uint64_t > : : iterator >
prepicked_compaction - > compaction - > ReleaseCompactionFiles (
pending_outputs_inserted_elem ( new std : : list < uint64_t > : : iterator (
Status : : Incomplete ( Status : : SubCode : : kManualCompactionPaused ) ) ;
CaptureCurrentFileNumberInPendingOutputs ( ) ) ) ;
delete prepicked_compaction - > compaction ;
} else {
assert ( ( bg_thread_pri = = Env : : Priority : : BOTTOM & &
JobContext job_context ( next_job_id_ . fetch_add ( 1 ) , true ) ;
bg_bottom_compaction_scheduled_ ) | |
// This call will unlock/lock the mutex to wait for current running
( bg_thread_pri = = Env : : Priority : : LOW & & bg_compaction_scheduled_ ) ) ;
// IngestExternalFile() calls to finish.
Status s = BackgroundCompaction ( & made_progress , & job_context , & log_buffer ,
WaitForIngestFile ( ) ;
prepicked_compaction , bg_thread_pri ) ;
TEST_SYNC_POINT ( " BackgroundCallCompaction:1 " ) ;
num_running_compactions_ + + ;
if ( s . IsBusy ( ) ) {
bg_cv_ . SignalAll ( ) ; // In case a waiter can proceed despite the error
std : : unique_ptr < std : : list < uint64_t > : : iterator >
mutex_ . Unlock ( ) ;
pending_outputs_inserted_elem ( new std : : list < uint64_t > : : iterator (
immutable_db_options_ . clock - > SleepForMicroseconds (
CaptureCurrentFileNumberInPendingOutputs ( ) ) ) ;
10000 ) ; // prevent hot loop
mutex_ . Lock ( ) ;
assert ( ( bg_thread_pri = = Env : : Priority : : BOTTOM & &
} else if ( ! s . ok ( ) & & ! s . IsShutdownInProgress ( ) & &
bg_bottom_compaction_scheduled_ ) | |
! s . IsManualCompactionPaused ( ) & & ! s . IsColumnFamilyDropped ( ) ) {
( bg_thread_pri = = Env : : Priority : : LOW & & bg_compaction_scheduled_ ) ) ;
// Wait a little bit before retrying background compaction in
Status s = BackgroundCompaction ( & made_progress , & job_context , & log_buffer ,
// case this is an environmental problem and we do not want to
prepicked_compaction , bg_thread_pri ) ;
// chew up resources for failed compactions for the duration of
TEST_SYNC_POINT ( " BackgroundCallCompaction:1 " ) ;
// the problem.
if ( s . IsBusy ( ) ) {
uint64_t error_cnt =
bg_cv_ . SignalAll ( ) ; // In case a waiter can proceed despite the error
default_cf_internal_stats_ - > BumpAndGetBackgroundErrorCount ( ) ;
mutex_ . Unlock ( ) ;
bg_cv_ . SignalAll ( ) ; // In case a waiter can proceed despite the error
immutable_db_options_ . clock - > SleepForMicroseconds (
mutex_ . Unlock ( ) ;
10000 ) ; // prevent hot loop
log_buffer . FlushBufferToLog ( ) ;
mutex_ . Lock ( ) ;
ROCKS_LOG_ERROR ( immutable_db_options_ . info_log ,
} else if ( ! s . ok ( ) & & ! s . IsShutdownInProgress ( ) & &
" Waiting after background compaction error: %s, "
! s . IsManualCompactionPaused ( ) & & ! s . IsColumnFamilyDropped ( ) ) {
" Accumulated background error counts: % " PRIu64 ,
// Wait a little bit before retrying background compaction in
s . ToString ( ) . c_str ( ) , error_cnt ) ;
// case this is an environmental problem and we do not want to
LogFlush ( immutable_db_options_ . info_log ) ;
// chew up resources for failed compactions for the duration of
immutable_db_options_ . clock - > SleepForMicroseconds ( 1000000 ) ;
// the problem.
mutex_ . Lock ( ) ;
uint64_t error_cnt =
} else if ( s . IsManualCompactionPaused ( ) ) {
default_cf_internal_stats_ - > BumpAndGetBackgroundErrorCount ( ) ;
ManualCompactionState * m = prepicked_compaction - > manual_compaction_state ;
bg_cv_ . SignalAll ( ) ; // In case a waiter can proceed despite the error
assert ( m ) ;
mutex_ . Unlock ( ) ;
ROCKS_LOG_BUFFER ( & log_buffer , " [%s] [JOB %d] Manual compaction paused " ,
log_buffer . FlushBufferToLog ( ) ;
m - > cfd - > GetName ( ) . c_str ( ) , job_context . job_id ) ;
ROCKS_LOG_ERROR ( immutable_db_options_ . info_log ,
}
" Waiting after background compaction error: %s, "
" Accumulated background error counts: % " PRIu64 ,
ReleaseFileNumberFromPendingOutputs ( pending_outputs_inserted_elem ) ;
s . ToString ( ) . c_str ( ) , error_cnt ) ;
LogFlush ( immutable_db_options_ . info_log ) ;
// If compaction failed, we want to delete all temporary files that we might
immutable_db_options_ . clock - > SleepForMicroseconds ( 1000000 ) ;
// have created (they might not be all recorded in job_context in case of a
mutex_ . Lock ( ) ;
// failure). Thus, we force full scan in FindObsoleteFiles()
} else if ( s . IsManualCompactionPaused ( ) ) {
FindObsoleteFiles ( & job_context , ! s . ok ( ) & & ! s . IsShutdownInProgress ( ) & &
assert ( prepicked_compaction ) ;
! s . IsManualCompactionPaused ( ) & &
ManualCompactionState * m =
! s . IsColumnFamilyDropped ( ) & &
prepicked_compaction - > manual_compaction_state ;
! s . IsBusy ( ) ) ;
assert ( m ) ;
TEST_SYNC_POINT ( " DBImpl::BackgroundCallCompaction:FoundObsoleteFiles " ) ;
ROCKS_LOG_BUFFER ( & log_buffer , " [%s] [JOB %d] Manual compaction paused " ,
m - > cfd - > GetName ( ) . c_str ( ) , job_context . job_id ) ;
// delete unnecessary files if any, this is done outside the mutex
}
if ( job_context . HaveSomethingToClean ( ) | |
job_context . HaveSomethingToDelete ( ) | | ! log_buffer . IsEmpty ( ) ) {
ReleaseFileNumberFromPendingOutputs ( pending_outputs_inserted_elem ) ;
mutex_ . Unlock ( ) ;
// Have to flush the info logs before bg_compaction_scheduled_--
// If compaction failed, we want to delete all temporary files that we
// because if bg_flush_scheduled_ becomes 0 and the lock is
// might have created (they might not be all recorded in job_context in
// released, the deconstructor of DB can kick in and destroy all the
// case of a failure). Thus, we force full scan in FindObsoleteFiles()
// states of DB so info_log might not be available after that point.
FindObsoleteFiles ( & job_context , ! s . ok ( ) & & ! s . IsShutdownInProgress ( ) & &
// It also applies to access other states that DB owns.
! s . IsManualCompactionPaused ( ) & &
log_buffer . FlushBufferToLog ( ) ;
! s . IsColumnFamilyDropped ( ) & &
if ( job_context . HaveSomethingToDelete ( ) ) {
! s . IsBusy ( ) ) ;
PurgeObsoleteFiles ( job_context ) ;
TEST_SYNC_POINT ( " DBImpl::BackgroundCallCompaction:FoundObsoleteFiles " ) ;
TEST_SYNC_POINT ( " DBImpl::BackgroundCallCompaction:PurgedObsoleteFiles " ) ;
// delete unnecessary files if any, this is done outside the mutex
if ( job_context . HaveSomethingToClean ( ) | |
job_context . HaveSomethingToDelete ( ) | | ! log_buffer . IsEmpty ( ) ) {
mutex_ . Unlock ( ) ;
// Have to flush the info logs before bg_compaction_scheduled_--
// because if bg_flush_scheduled_ becomes 0 and the lock is
// released, the deconstructor of DB can kick in and destroy all the
// states of DB so info_log might not be available after that point.
// It also applies to access other states that DB owns.
log_buffer . FlushBufferToLog ( ) ;
if ( job_context . HaveSomethingToDelete ( ) ) {
PurgeObsoleteFiles ( job_context ) ;
TEST_SYNC_POINT (
" DBImpl::BackgroundCallCompaction:PurgedObsoleteFiles " ) ;
}
job_context . Clean ( ) ;
mutex_ . Lock ( ) ;
}
}
job_context . Clean ( ) ;
mutex_ . Lock ( ) ;
assert ( num_running_compactions_ > 0 ) ;
num_running_compactions_ - - ;
}
}
assert ( num_running_compactions_ > 0 ) ;
num_running_compactions_ - - ;
if ( bg_thread_pri = = Env : : Priority : : LOW ) {
if ( bg_thread_pri = = Env : : Priority : : LOW ) {
bg_compaction_scheduled_ - - ;
bg_compaction_scheduled_ - - ;
} else {
} else {
@ -2943,7 +2969,6 @@ void DBImpl::BackgroundCallCompaction(PrepickedCompaction* prepicked_compaction,
// must be done before we potentially signal the DB close process to
// must be done before we potentially signal the DB close process to
// proceed below.
// proceed below.
prepicked_compaction - > task_token . reset ( ) ;
prepicked_compaction - > task_token . reset ( ) ;
;
}
}
if ( made_progress | |
if ( made_progress | |