Backport #22264 ยป compaction_picker_test.diff
db/compaction_picker_test.cc | ||
---|---|---|
ASSERT_EQ(4, vstorage_->NextCompactionIndex(1 /* level */));
|
||
}
|
||
uint32_t GetPathId(
|
||
const ImmutableCFOptions& ioptions,
|
||
const MutableCFOptions& mutable_cf_options, int level) {
|
||
uint32_t p = 0;
|
||
assert(!ioptions.db_paths.empty());
|
||
// size remaining in the most recent path
|
||
uint64_t current_path_size = ioptions.db_paths[0].target_size;
|
||
uint64_t level_size;
|
||
int cur_level = 0;
|
||
// max_bytes_for_level_base denotes L1 size.
|
||
// We estimate L0 size to be the same as L1.
|
||
level_size = mutable_cf_options.max_bytes_for_level_base;
|
||
// Last path is the fallback
|
||
while (p < ioptions.db_paths.size() - 1) {
|
||
if (level_size <= current_path_size) {
|
||
if (cur_level == level) {
|
||
// Does desired level fit in this path?
|
||
return p;
|
||
} else {
|
||
current_path_size -= level_size;
|
||
if (cur_level > 0) {
|
||
if (ioptions.level_compaction_dynamic_level_bytes) {
|
||
// Currently, level_compaction_dynamic_level_bytes is ignored when
|
||
// multiple db paths are specified. https://github.com/facebook/
|
||
// rocksdb/blob/master/db/column_family.cc.
|
||
// Still, adding this check to avoid accidentally using
|
||
// max_bytes_for_level_multiplier_additional
|
||
level_size = static_cast<uint64_t>(
|
||
level_size * mutable_cf_options.max_bytes_for_level_multiplier);
|
||
} else {
|
||
level_size = static_cast<uint64_t>(
|
||
level_size * mutable_cf_options.max_bytes_for_level_multiplier
|
||
* mutable_cf_options.MaxBytesMultiplerAdditional(cur_level));
|
||
}
|
||
}
|
||
cur_level++;
|
||
continue;
|
||
}
|
||
}
|
||
p++;
|
||
current_path_size = ioptions.db_paths[p].target_size;
|
||
}
|
||
return p;
|
||
}
|
||
uint32_t GetPathId12(
|
||
const ImmutableCFOptions& ioptions,
|
||
const MutableCFOptions& mutable_cf_options, int level) {
|
||
uint32_t p = 0;
|
||
assert(!ioptions.db_paths.empty());
|
||
// size remaining in the most recent path
|
||
uint64_t current_path_size = ioptions.db_paths[0].target_size;
|
||
uint64_t level_size;
|
||
int cur_level = 0;
|
||
level_size = mutable_cf_options.max_bytes_for_level_base;
|
||
// Last path is the fallback
|
||
while (p < ioptions.db_paths.size() - 1) {
|
||
if (level_size <= current_path_size) {
|
||
if (cur_level == level) {
|
||
// Does desired level fit in this path?
|
||
return p;
|
||
} else {
|
||
current_path_size -= level_size;
|
||
level_size = static_cast<uint64_t>(
|
||
level_size * mutable_cf_options.max_bytes_for_level_multiplier);
|
||
cur_level++;
|
||
continue;
|
||
}
|
||
}
|
||
p++;
|
||
current_path_size = ioptions.db_paths[p].target_size;
|
||
}
|
||
return p;
|
||
}
|
||
TEST_F(CompactionPickerTest, GetPathId) {
|
||
mutable_cf_options_.max_bytes_for_level_base = 250u * 1024 * 1024;
|
||
mutable_cf_options_.max_bytes_for_level_multiplier = 10;
|
||
ioptions_.level_compaction_dynamic_level_bytes = false;
|
||
ioptions_.db_paths.resize(2);
|
||
ioptions_.db_paths[0].target_size = uint64_t(50u) * 1024 * 1024 * 1024;
|
||
ioptions_.db_paths[1].target_size = uint64_t(280) * 1024 * 1024 * 1024;
|
||
ASSERT_EQ(0, GetPathId(ioptions_, mutable_cf_options_, 1));
|
||
ASSERT_EQ(0, GetPathId(ioptions_, mutable_cf_options_, 3));
|
||
ASSERT_EQ(1, GetPathId(ioptions_, mutable_cf_options_, 4));
|
||
ASSERT_EQ(0, GetPathId12(ioptions_, mutable_cf_options_, 1));
|
||
ASSERT_EQ(0, GetPathId12(ioptions_, mutable_cf_options_, 3));
|
||
ASSERT_EQ(1, GetPathId12(ioptions_, mutable_cf_options_, 4));
|
||
}
|
||
} // namespace rocksdb
|
||
int main(int argc, char** argv) {
|