Re-enable SuggestCompactRangeTest and add Universal Compaction test (#10473)

Summary:
The feature `SuggestCompactRange()` is still experimental. Just
re-add the test back.

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

Test Plan: CI

Reviewed By: akankshamahajan15

Differential Revision: D38427153

Pulled By: jay-zhuang

fbshipit-source-id: 0b4491c947cbce6c18ff147b167e3c678633129a
main
Jay Zhuang 2 years ago committed by Facebook GitHub Bot
parent 56dbcb4f72
commit edae671ce0
  1. 89
      db/db_test.cc

@ -5968,7 +5968,7 @@ TEST_F(DBTest, EmptyCompactedDB) {
#endif // ROCKSDB_LITE
#ifndef ROCKSDB_LITE
TEST_F(DBTest, DISABLED_SuggestCompactRangeTest) {
TEST_F(DBTest, SuggestCompactRangeTest) {
class CompactionFilterFactoryGetContext : public CompactionFilterFactory {
public:
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
@ -6007,51 +6007,86 @@ TEST_F(DBTest, DISABLED_SuggestCompactRangeTest) {
Random rnd(301);
for (int num = 0; num < 3; num++) {
for (int num = 0; num < 10; num++) {
GenerateNewRandomFile(&rnd);
}
GenerateNewRandomFile(&rnd);
ASSERT_EQ("0,4", FilesPerLevel(0));
ASSERT_TRUE(!CompactionFilterFactoryGetContext::IsManual(
options.compaction_filter_factory.get()));
GenerateNewRandomFile(&rnd);
ASSERT_EQ("1,4", FilesPerLevel(0));
// make sure either L0 or L1 has file
while (NumTableFilesAtLevel(0) == 0 && NumTableFilesAtLevel(1) == 0) {
GenerateNewRandomFile(&rnd);
}
GenerateNewRandomFile(&rnd);
ASSERT_EQ("2,4", FilesPerLevel(0));
// compact it three times
for (int i = 0; i < 3; ++i) {
ASSERT_OK(experimental::SuggestCompactRange(db_, nullptr, nullptr));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
}
GenerateNewRandomFile(&rnd);
ASSERT_EQ("3,4", FilesPerLevel(0));
// All files are compacted
ASSERT_EQ(0, NumTableFilesAtLevel(0));
ASSERT_EQ(0, NumTableFilesAtLevel(1));
GenerateNewRandomFile(&rnd);
ASSERT_EQ("0,4,4", FilesPerLevel(0));
ASSERT_EQ(1, NumTableFilesAtLevel(0));
GenerateNewRandomFile(&rnd);
ASSERT_EQ("1,4,4", FilesPerLevel(0));
// nonoverlapping with the file on level 0
Slice start("a"), end("b");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
GenerateNewRandomFile(&rnd);
ASSERT_EQ("2,4,4", FilesPerLevel(0));
// should not compact the level 0 file
ASSERT_EQ(1, NumTableFilesAtLevel(0));
GenerateNewRandomFile(&rnd);
ASSERT_EQ("3,4,4", FilesPerLevel(0));
start = Slice("j");
end = Slice("m");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
// SuggestCompactRange() is not going to be reported as manual compaction
ASSERT_TRUE(!CompactionFilterFactoryGetContext::IsManual(
options.compaction_filter_factory.get()));
GenerateNewRandomFile(&rnd);
ASSERT_EQ("0,4,8", FilesPerLevel(0));
// now it should compact the level 0 file
// as it's a trivial move to L1, it triggers another one to compact to L2
ASSERT_EQ(0, NumTableFilesAtLevel(0));
ASSERT_EQ(0, NumTableFilesAtLevel(1));
}
GenerateNewRandomFile(&rnd);
ASSERT_EQ("1,4,8", FilesPerLevel(0));
TEST_F(DBTest, SuggestCompactRangeUniversal) {
Options options = CurrentOptions();
options.memtable_factory.reset(test::NewSpecialSkipListFactory(
DBTestBase::kNumKeysByGenerateNewRandomFile));
options.compaction_style = kCompactionStyleUniversal;
options.write_buffer_size = 200 << 10;
options.arena_block_size = 4 << 10;
options.level0_file_num_compaction_trigger = 4;
options.num_levels = 4;
options.compression = kNoCompression;
options.max_bytes_for_level_base = 450 << 10;
options.target_file_size_base = 98 << 10;
options.max_compaction_bytes = static_cast<uint64_t>(1) << 60; // inf
// compact it three times
for (int i = 0; i < 3; ++i) {
ASSERT_OK(experimental::SuggestCompactRange(db_, nullptr, nullptr));
Reopen(options);
Random rnd(301);
for (int num = 0; num < 10; num++) {
GenerateNewRandomFile(&rnd);
}
ASSERT_EQ("1,2,3,4", FilesPerLevel());
for (int i = 0; i < 3; i++) {
ASSERT_OK(
db_->SuggestCompactRange(db_->DefaultColumnFamily(), nullptr, nullptr));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
}
// All files are compacted
ASSERT_EQ(0, NumTableFilesAtLevel(0));
ASSERT_EQ(0, NumTableFilesAtLevel(1));
ASSERT_EQ(0, NumTableFilesAtLevel(2));
GenerateNewRandomFile(&rnd);
ASSERT_EQ(1, NumTableFilesAtLevel(0));
@ -6068,12 +6103,10 @@ TEST_F(DBTest, DISABLED_SuggestCompactRangeTest) {
end = Slice("m");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
ASSERT_TRUE(CompactionFilterFactoryGetContext::IsManual(
options.compaction_filter_factory.get()));
// now it should compact the level 0 file
// now it should compact the level 0 file to the last level
ASSERT_EQ(0, NumTableFilesAtLevel(0));
ASSERT_EQ(1, NumTableFilesAtLevel(1));
ASSERT_EQ(0, NumTableFilesAtLevel(1));
}
TEST_F(DBTest, PromoteL0) {

Loading…
Cancel
Save