Avoid div-by-zero error in db_stress (#9086)

Summary:
If a column family has 0 levels, then existing `TestCompactFiles(...)` may hit
divide-by-zero. To fix, return early if the cf is empty.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9086

Test Plan: TBD

Reviewed By: ajkr

Differential Revision: D31986799

Pulled By: riversand963

fbshipit-source-id: 48f7dfb2b2b47cfc1315cb71ca80eb230d947f17
This commit is contained in:
Yanqin Jin 2021-10-31 22:13:05 -07:00 committed by Facebook GitHub Bot
parent 8e59a1dc9a
commit d263505417

View File

@ -1812,6 +1812,10 @@ void StressTest::TestCompactFiles(ThreadState* thread,
ROCKSDB_NAMESPACE::ColumnFamilyMetaData cf_meta_data;
db_->GetColumnFamilyMetaData(column_family, &cf_meta_data);
if (cf_meta_data.levels.empty()) {
return;
}
// Randomly compact up to three consecutive files from a level
const int kMaxRetry = 3;
for (int attempt = 0; attempt < kMaxRetry; ++attempt) {