@ -632,6 +632,41 @@ int GetL0ThresholdSpeedupCompaction(int level0_file_num_compaction_trigger,
}
}
} // namespace
} // namespace
std : : pair < WriteStallCondition , ColumnFamilyData : : WriteStallCause >
ColumnFamilyData : : GetWriteStallConditionAndCause (
int num_unflushed_memtables , int num_l0_files ,
uint64_t num_compaction_needed_bytes ,
const MutableCFOptions & mutable_cf_options ) {
if ( num_unflushed_memtables > = mutable_cf_options . max_write_buffer_number ) {
return { WriteStallCondition : : kStopped , WriteStallCause : : kMemtableLimit } ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
num_l0_files > = mutable_cf_options . level0_stop_writes_trigger ) {
return { WriteStallCondition : : kStopped , WriteStallCause : : kL0FileCountLimit } ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
mutable_cf_options . hard_pending_compaction_bytes_limit > 0 & &
num_compaction_needed_bytes > =
mutable_cf_options . hard_pending_compaction_bytes_limit ) {
return { WriteStallCondition : : kStopped ,
WriteStallCause : : kPendingCompactionBytes } ;
} else if ( mutable_cf_options . max_write_buffer_number > 3 & &
num_unflushed_memtables > =
mutable_cf_options . max_write_buffer_number - 1 ) {
return { WriteStallCondition : : kDelayed , WriteStallCause : : kMemtableLimit } ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
mutable_cf_options . level0_slowdown_writes_trigger > = 0 & &
num_l0_files > =
mutable_cf_options . level0_slowdown_writes_trigger ) {
return { WriteStallCondition : : kDelayed , WriteStallCause : : kL0FileCountLimit } ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
mutable_cf_options . soft_pending_compaction_bytes_limit > 0 & &
num_compaction_needed_bytes > =
mutable_cf_options . soft_pending_compaction_bytes_limit ) {
return { WriteStallCondition : : kDelayed ,
WriteStallCause : : kPendingCompactionBytes } ;
}
return { WriteStallCondition : : kNormal , WriteStallCause : : kNone } ;
}
WriteStallCondition ColumnFamilyData : : RecalculateWriteStallConditions (
WriteStallCondition ColumnFamilyData : : RecalculateWriteStallConditions (
const MutableCFOptions & mutable_cf_options ) {
const MutableCFOptions & mutable_cf_options ) {
auto write_stall_condition = WriteStallCondition : : kNormal ;
auto write_stall_condition = WriteStallCondition : : kNormal ;
@ -641,25 +676,29 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
uint64_t compaction_needed_bytes =
uint64_t compaction_needed_bytes =
vstorage - > estimated_compaction_needed_bytes ( ) ;
vstorage - > estimated_compaction_needed_bytes ( ) ;
auto write_stall_condition_and_cause = GetWriteStallConditionAndCause (
imm ( ) - > NumNotFlushed ( ) , vstorage - > l0_delay_trigger_count ( ) ,
vstorage - > estimated_compaction_needed_bytes ( ) , mutable_cf_options ) ;
write_stall_condition = write_stall_condition_and_cause . first ;
auto write_stall_cause = write_stall_condition_and_cause . second ;
bool was_stopped = write_controller - > IsStopped ( ) ;
bool was_stopped = write_controller - > IsStopped ( ) ;
bool needed_delay = write_controller - > NeedsDelay ( ) ;
bool needed_delay = write_controller - > NeedsDelay ( ) ;
if ( imm ( ) - > NumNotFlushed ( ) > = mutable_cf_options . max_write_buffer_number ) {
if ( write_stall_condition = = WriteStallCondition : : kStopped & &
write_stall_cause = = WriteStallCause : : kMemtableLimit ) {
write_controller_token_ = write_controller - > GetStopToken ( ) ;
write_controller_token_ = write_controller - > GetStopToken ( ) ;
internal_stats_ - > AddCFStats ( InternalStats : : MEMTABLE_LIMIT_STOPS , 1 ) ;
internal_stats_ - > AddCFStats ( InternalStats : : MEMTABLE_LIMIT_STOPS , 1 ) ;
write_stall_condition = WriteStallCondition : : kStopped ;
ROCKS_LOG_WARN (
ROCKS_LOG_WARN (
ioptions_ . info_log ,
ioptions_ . info_log ,
" [%s] Stopping writes because we have %d immutable memtables "
" [%s] Stopping writes because we have %d immutable memtables "
" (waiting for flush), max_write_buffer_number is set to %d " ,
" (waiting for flush), max_write_buffer_number is set to %d " ,
name_ . c_str ( ) , imm ( ) - > NumNotFlushed ( ) ,
name_ . c_str ( ) , imm ( ) - > NumNotFlushed ( ) ,
mutable_cf_options . max_write_buffer_number ) ;
mutable_cf_options . max_write_buffer_number ) ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
} else if ( write_stall_condition = = WriteStallCondition : : kStopped & &
vstorage - > l0_delay_trigger_count ( ) > =
write_stall_cause = = WriteStallCause : : kL0FileCountLimit ) {
mutable_cf_options . level0_stop_writes_trigger ) {
write_controller_token_ = write_controller - > GetStopToken ( ) ;
write_controller_token_ = write_controller - > GetStopToken ( ) ;
internal_stats_ - > AddCFStats ( InternalStats : : L0_FILE_COUNT_LIMIT_STOPS , 1 ) ;
internal_stats_ - > AddCFStats ( InternalStats : : L0_FILE_COUNT_LIMIT_STOPS , 1 ) ;
write_stall_condition = WriteStallCondition : : kStopped ;
if ( compaction_picker_ - > IsLevel0CompactionInProgress ( ) ) {
if ( compaction_picker_ - > IsLevel0CompactionInProgress ( ) ) {
internal_stats_ - > AddCFStats (
internal_stats_ - > AddCFStats (
InternalStats : : LOCKED_L0_FILE_COUNT_LIMIT_STOPS , 1 ) ;
InternalStats : : LOCKED_L0_FILE_COUNT_LIMIT_STOPS , 1 ) ;
@ -667,28 +706,23 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
ROCKS_LOG_WARN ( ioptions_ . info_log ,
ROCKS_LOG_WARN ( ioptions_ . info_log ,
" [%s] Stopping writes because we have %d level-0 files " ,
" [%s] Stopping writes because we have %d level-0 files " ,
name_ . c_str ( ) , vstorage - > l0_delay_trigger_count ( ) ) ;
name_ . c_str ( ) , vstorage - > l0_delay_trigger_count ( ) ) ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
} else if ( write_stall_condition = = WriteStallCondition : : kStopped & &
mutable_cf_options . hard_pending_compaction_bytes_limit > 0 & &
write_stall_cause = = WriteStallCause : : kPendingCompactionBytes ) {
compaction_needed_bytes > =
mutable_cf_options . hard_pending_compaction_bytes_limit ) {
write_controller_token_ = write_controller - > GetStopToken ( ) ;
write_controller_token_ = write_controller - > GetStopToken ( ) ;
internal_stats_ - > AddCFStats (
internal_stats_ - > AddCFStats (
InternalStats : : PENDING_COMPACTION_BYTES_LIMIT_STOPS , 1 ) ;
InternalStats : : PENDING_COMPACTION_BYTES_LIMIT_STOPS , 1 ) ;
write_stall_condition = WriteStallCondition : : kStopped ;
ROCKS_LOG_WARN (
ROCKS_LOG_WARN (
ioptions_ . info_log ,
ioptions_ . info_log ,
" [%s] Stopping writes because of estimated pending compaction "
" [%s] Stopping writes because of estimated pending compaction "
" bytes % " PRIu64 ,
" bytes % " PRIu64 ,
name_ . c_str ( ) , compaction_needed_bytes ) ;
name_ . c_str ( ) , compaction_needed_bytes ) ;
} else if ( mutable_cf_options . max_write_buffer_number > 3 & &
} else if ( write_stall_condition = = WriteStallCondition : : kDelayed & &
imm ( ) - > NumNotFlushed ( ) > =
write_stall_cause = = WriteStallCause : : kMemtableLimit ) {
mutable_cf_options . max_write_buffer_number - 1 ) {
write_controller_token_ =
write_controller_token_ =
SetupDelay ( write_controller , compaction_needed_bytes ,
SetupDelay ( write_controller , compaction_needed_bytes ,
prev_compaction_needed_bytes_ , was_stopped ,
prev_compaction_needed_bytes_ , was_stopped ,
mutable_cf_options . disable_auto_compactions ) ;
mutable_cf_options . disable_auto_compactions ) ;
internal_stats_ - > AddCFStats ( InternalStats : : MEMTABLE_LIMIT_SLOWDOWNS , 1 ) ;
internal_stats_ - > AddCFStats ( InternalStats : : MEMTABLE_LIMIT_SLOWDOWNS , 1 ) ;
write_stall_condition = WriteStallCondition : : kDelayed ;
ROCKS_LOG_WARN (
ROCKS_LOG_WARN (
ioptions_ . info_log ,
ioptions_ . info_log ,
" [%s] Stalling writes because we have %d immutable memtables "
" [%s] Stalling writes because we have %d immutable memtables "
@ -697,10 +731,8 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
name_ . c_str ( ) , imm ( ) - > NumNotFlushed ( ) ,
name_ . c_str ( ) , imm ( ) - > NumNotFlushed ( ) ,
mutable_cf_options . max_write_buffer_number ,
mutable_cf_options . max_write_buffer_number ,
write_controller - > delayed_write_rate ( ) ) ;
write_controller - > delayed_write_rate ( ) ) ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
} else if ( write_stall_condition = = WriteStallCondition : : kDelayed & &
mutable_cf_options . level0_slowdown_writes_trigger > = 0 & &
write_stall_cause = = WriteStallCause : : kL0FileCountLimit ) {
vstorage - > l0_delay_trigger_count ( ) > =
mutable_cf_options . level0_slowdown_writes_trigger ) {
// L0 is the last two files from stopping.
// L0 is the last two files from stopping.
bool near_stop = vstorage - > l0_delay_trigger_count ( ) > =
bool near_stop = vstorage - > l0_delay_trigger_count ( ) > =
mutable_cf_options . level0_stop_writes_trigger - 2 ;
mutable_cf_options . level0_stop_writes_trigger - 2 ;
@ -710,7 +742,6 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
mutable_cf_options . disable_auto_compactions ) ;
mutable_cf_options . disable_auto_compactions ) ;
internal_stats_ - > AddCFStats ( InternalStats : : L0_FILE_COUNT_LIMIT_SLOWDOWNS ,
internal_stats_ - > AddCFStats ( InternalStats : : L0_FILE_COUNT_LIMIT_SLOWDOWNS ,
1 ) ;
1 ) ;
write_stall_condition = WriteStallCondition : : kDelayed ;
if ( compaction_picker_ - > IsLevel0CompactionInProgress ( ) ) {
if ( compaction_picker_ - > IsLevel0CompactionInProgress ( ) ) {
internal_stats_ - > AddCFStats (
internal_stats_ - > AddCFStats (
InternalStats : : LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS , 1 ) ;
InternalStats : : LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS , 1 ) ;
@ -720,10 +751,8 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
" rate % " PRIu64 ,
" rate % " PRIu64 ,
name_ . c_str ( ) , vstorage - > l0_delay_trigger_count ( ) ,
name_ . c_str ( ) , vstorage - > l0_delay_trigger_count ( ) ,
write_controller - > delayed_write_rate ( ) ) ;
write_controller - > delayed_write_rate ( ) ) ;
} else if ( ! mutable_cf_options . disable_auto_compactions & &
} else if ( write_stall_condition = = WriteStallCondition : : kDelayed & &
mutable_cf_options . soft_pending_compaction_bytes_limit > 0 & &
write_stall_cause = = WriteStallCause : : kPendingCompactionBytes ) {
vstorage - > estimated_compaction_needed_bytes ( ) > =
mutable_cf_options . soft_pending_compaction_bytes_limit ) {
// If the distance to hard limit is less than 1/4 of the gap between soft
// If the distance to hard limit is less than 1/4 of the gap between soft
// and
// and
// hard bytes limit, we think it is near stop and speed up the slowdown.
// hard bytes limit, we think it is near stop and speed up the slowdown.
@ -741,7 +770,6 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
mutable_cf_options . disable_auto_compactions ) ;
mutable_cf_options . disable_auto_compactions ) ;
internal_stats_ - > AddCFStats (
internal_stats_ - > AddCFStats (
InternalStats : : PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS , 1 ) ;
InternalStats : : PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS , 1 ) ;
write_stall_condition = WriteStallCondition : : kDelayed ;
ROCKS_LOG_WARN (
ROCKS_LOG_WARN (
ioptions_ . info_log ,
ioptions_ . info_log ,
" [%s] Stalling writes because of estimated pending compaction "
" [%s] Stalling writes because of estimated pending compaction "
@ -749,6 +777,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
name_ . c_str ( ) , vstorage - > estimated_compaction_needed_bytes ( ) ,
name_ . c_str ( ) , vstorage - > estimated_compaction_needed_bytes ( ) ,
write_controller - > delayed_write_rate ( ) ) ;
write_controller - > delayed_write_rate ( ) ) ;
} else {
} else {
assert ( write_stall_condition = = WriteStallCondition : : kNormal ) ;
if ( vstorage - > l0_delay_trigger_count ( ) > =
if ( vstorage - > l0_delay_trigger_count ( ) > =
GetL0ThresholdSpeedupCompaction (
GetL0ThresholdSpeedupCompaction (
mutable_cf_options . level0_file_num_compaction_trigger ,
mutable_cf_options . level0_file_num_compaction_trigger ,