diff --git a/db/column_family.cc b/db/column_family.cc index b27d70e71c..2002783408 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -571,30 +571,26 @@ int GetL0ThresholdSpeedupCompaction(int level0_file_num_compaction_trigger, return std::numeric_limits::max(); } - const int twice_level0_trigger = level0_file_num_compaction_trigger * 2; + const int64_t twice_level0_trigger = + static_cast(level0_file_num_compaction_trigger) * 2; - // overflow protection - if (twice_level0_trigger < 0) { - return std::numeric_limits::max(); - } - - // 1/4 of the way between L0 compaction trigger threshold and slowdown - // condition. - const int one_fourth_trigger_slowdown = - level0_file_num_compaction_trigger + + const int64_t one_fourth_trigger_slowdown = + static_cast(level0_file_num_compaction_trigger) + ((level0_slowdown_writes_trigger - level0_file_num_compaction_trigger) / 4); - // overflow protection - if (one_fourth_trigger_slowdown < 0) { - return std::numeric_limits::max(); - } - assert(twice_level0_trigger >= 0); assert(one_fourth_trigger_slowdown >= 0); + // 1/4 of the way between L0 compaction trigger threshold and slowdown + // condition. // Or twice as compaction trigger, if it is smaller. - return std::min(twice_level0_trigger, one_fourth_trigger_slowdown); + int64_t res = std::min(twice_level0_trigger, one_fourth_trigger_slowdown); + if (res >= port::kMaxInt32) { + return port::kMaxInt32; + } else { + return res; + } } } // namespace