Skip to content

Commit 0be850a

Browse files
Xingbo Wangfacebook-github-bot
authored andcommitted
Avoid divide by 0 in ComputeCompactionScore for FIFO compaction (facebook#13767)
Summary: When max_table_files_size was accidentally configured with 0 value, engine could crash on divide by 0 operation. Although RocksDB do configuration validation during bootstrap, it typically does not do this for runtime dynamic parameter validation. Therefore, there is a chance where max_table_files_size could be set to 0. This PR only focuses on fixing a code path where max_table_files_size ack as divisor. Pull Request resolved: facebook#13767 Test Plan: Unit test. Reviewed By: cbi42 Differential Revision: D78420516 Pulled By: xingbowang fbshipit-source-id: 6fdcc85b28a2c6319066665262b981e513719703
1 parent e46972d commit 0be850a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

db/version_set.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,8 +3509,13 @@ void VersionStorageInfo::ComputeCompactionScore(
35093509
}
35103510

35113511
if (compaction_style_ == kCompactionStyleFIFO) {
3512-
score = static_cast<double>(total_size) /
3513-
mutable_cf_options.compaction_options_fifo.max_table_files_size;
3512+
auto max_table_files_size =
3513+
mutable_cf_options.compaction_options_fifo.max_table_files_size;
3514+
if (max_table_files_size == 0) {
3515+
// avoid divide 0
3516+
max_table_files_size = 1;
3517+
}
3518+
score = static_cast<double>(total_size) / max_table_files_size;
35143519
if (score < 1 &&
35153520
mutable_cf_options.compaction_options_fifo.allow_compaction) {
35163521
score = std::max(

0 commit comments

Comments
 (0)