Skip to content

Instantly share code, notes, and snippets.

@ajkr
Created November 12, 2016 01:05
Show Gist options
  • Save ajkr/63c7eae3e9667c5ebdc0a7efb74ac332 to your computer and use it in GitHub Desktop.
Save ajkr/63c7eae3e9667c5ebdc0a7efb74ac332 to your computer and use it in GitHub Desktop.
diff --git a/db/db_range_del_test.cc b/db/db_range_del_test.cc
index 47f829a..486a05d 100644
--- a/db/db_range_del_test.cc
+++ b/db/db_range_del_test.cc
@@ -188,6 +188,51 @@ TEST_F(DBRangeDelTest, CompactionRemovesCoveredKeys) {
}
}
+TEST_F(DBRangeDelTest, ValidLevelSubcompactionBoundaries) {
+ const int kNumPerFile = 100, kNumFiles = 4, kFileBytes = 100 << 10;
+ Options options = CurrentOptions();
+ options.level0_file_num_compaction_trigger = kNumFiles;
+ options.max_bytes_for_level_base = 2 * kFileBytes;
+ options.max_subcompactions = 4;
+ options.memtable_factory.reset(new SpecialSkipListFactory(kNumPerFile));
+ options.num_levels = 3;
+ options.target_file_size_base = kFileBytes;
+ options.target_file_size_multiplier = 1;
+ Reopen(options);
+
+ Random rnd(301);
+ for (int i = 0; i < 2; ++i) {
+ for (int j = 0; j < kNumFiles; ++j) {
+ if (i > 0) {
+ // delete [95,105) in two files, [295,305) in next two
+ int mid = (j + (1 - j % 2)) * kNumPerFile;
+ db_->DeleteRange(WriteOptions(), Key(mid - 5), Key(mid + 5));
+ }
+ std::vector<std::string> values;
+ // Write 100KB (100 values, each 1K)
+ for (int k = 0; k < kNumPerFile; k++) {
+ values.push_back(RandomString(&rnd, 990));
+ ASSERT_OK(Put(Key(j * kNumPerFile + k), values[k]));
+ }
+ // put extra key to trigger flush
+ ASSERT_OK(Put("", ""));
+ dbfull()->TEST_WaitForFlushMemTable();
+ ASSERT_EQ(NumTableFilesAtLevel(0), j + 1);
+ if (j == options.level0_file_num_compaction_trigger - 1) {
+ // When i == 1, compaction will output some files to L1, at which point
+ // L1 is not bottommost so range deletions cannot be compacted away. The
+ // new L1 files must be generated with non-overlapping key ranges even
+ // though multiple subcompactions see the same ranges deleted, else an
+ // assertion will fail.
+ dbfull()->TEST_WaitForCompact();
+ ASSERT_EQ(NumTableFilesAtLevel(0), 0);
+ ASSERT_GT(NumTableFilesAtLevel(1), 0);
+ ASSERT_GT(NumTableFilesAtLevel(2), 0);
+ }
+ }
+ }
+}
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment