Add a test in compaction_picker_test to test the max score

Summary: Add a new unit test in compaction_picker_test to make sure level-based compaction to pick up the level with the largest score.

Test Plan: Run the new test

Reviewers: ljin, yhchiang, rven, igor

Reviewed By: igor

Subscribers: leveldb, dhruba

Differential Revision: https://reviews.facebook.net/D27933
main
sdong 10 years ago
parent 86de2007b8
commit 5c82a8837e
  1. 29
      db/compaction_picker_test.cc

@ -129,9 +129,9 @@ TEST(CompactionPickerTest, Level1Trigger) {
TEST(CompactionPickerTest, Level1Trigger2) { TEST(CompactionPickerTest, Level1Trigger2) {
Add(1, 66U, "150", "200", 1000000000U); Add(1, 66U, "150", "200", 1000000000U);
Add(1, 88U, "201", "300", 1000000000U); Add(1, 88U, "201", "300", 1000000000U);
Add(2, 6U, "150", "180", 1000000000U); Add(2, 6U, "150", "179", 1000000000U);
Add(2, 7U, "180", "220", 1000000000U); Add(2, 7U, "180", "220", 1000000000U);
Add(2, 8U, "220", "300", 1000000000U); Add(2, 8U, "221", "300", 1000000000U);
UpdateVersionStorageInfo(); UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction( std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
@ -144,6 +144,31 @@ TEST(CompactionPickerTest, Level1Trigger2) {
ASSERT_EQ(7U, compaction->input(1, 1)->fd.GetNumber()); ASSERT_EQ(7U, compaction->input(1, 1)->fd.GetNumber());
} }
TEST(CompactionPickerTest, LevelMaxScore) {
mutable_cf_options.target_file_size_base = 10000000;
mutable_cf_options.target_file_size_multiplier = 10;
Add(0, 1U, "150", "200", 1000000000U);
// Level 1 score 1.2
Add(1, 66U, "150", "200", 6000000U);
Add(1, 88U, "201", "300", 6000000U);
// Level 2 score 1.8. File 7 is the largest. Should be picked
Add(2, 6U, "150", "179", 60000000U);
Add(2, 7U, "180", "220", 60000001U);
Add(2, 8U, "221", "300", 60000000U);
// Level 3 score slightly larger than 1
Add(3, 26U, "150", "170", 260000000U);
Add(3, 27U, "171", "179", 260000000U);
Add(3, 28U, "191", "220", 260000000U);
Add(3, 29U, "221", "300", 260000000U);
UpdateVersionStorageInfo();
std::unique_ptr<Compaction> compaction(level_compaction_picker.PickCompaction(
cf_name, mutable_cf_options, &vstorage, &log_buffer));
ASSERT_TRUE(compaction.get() != nullptr);
ASSERT_EQ(1, compaction->num_input_files(0));
ASSERT_EQ(7U, compaction->input(0, 0)->fd.GetNumber());
}
} // namespace rocksdb } // namespace rocksdb
int main(int argc, char** argv) { return rocksdb::test::RunAllTests(); } int main(int argc, char** argv) { return rocksdb::test::RunAllTests(); }

Loading…
Cancel
Save