Parameterize DBBasicTest.CompactBetweenSnapshots (#7301)

Summary:
DBBasicTest.CompactBetweenSnapshots can time-out in some slow-I/O hosts. Parameterize it so that single test runs shorter.

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

Test Plan: Run the test and see see different runs are of different configerations in a hacky way.

Reviewed By: ltamasi

Differential Revision: D23277733

fbshipit-source-id: 1f717b4131322d175abf9e211131fe7e9b1ef758
main
sdong 4 years ago committed by Facebook GitHub Bot
parent d51f88c9e4
commit cecdd5d2ab
  1. 117
      db/db_basic_test.cc

@ -664,60 +664,77 @@ TEST_F(DBBasicTest, Snapshot) {
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE
TEST_F(DBBasicTest, CompactBetweenSnapshots) { class DBBasicMultiConfigs : public DBBasicTest,
anon::OptionsOverride options_override; public ::testing::WithParamInterface<int> {
options_override.skip_policy = kSkipNoSnapshot; public:
do { DBBasicMultiConfigs() { option_config_ = GetParam(); }
Options options = CurrentOptions(options_override);
options.disable_auto_compactions = true;
CreateAndReopenWithCF({"pikachu"}, options);
Random rnd(301);
FillLevels("a", "z", 1);
Put(1, "foo", "first");
const Snapshot* snapshot1 = db_->GetSnapshot();
Put(1, "foo", "second");
Put(1, "foo", "third");
Put(1, "foo", "fourth");
const Snapshot* snapshot2 = db_->GetSnapshot();
Put(1, "foo", "fifth");
Put(1, "foo", "sixth");
// All entries (including duplicates) exist
// before any compaction or flush is triggered.
ASSERT_EQ(AllEntriesFor("foo", 1),
"[ sixth, fifth, fourth, third, second, first ]");
ASSERT_EQ("sixth", Get(1, "foo"));
ASSERT_EQ("fourth", Get(1, "foo", snapshot2));
ASSERT_EQ("first", Get(1, "foo", snapshot1));
// After a flush, "second", "third" and "fifth" should
// be removed
ASSERT_OK(Flush(1));
ASSERT_EQ(AllEntriesFor("foo", 1), "[ sixth, fourth, first ]");
// after we release the snapshot1, only two values left
db_->ReleaseSnapshot(snapshot1);
FillLevels("a", "z", 1);
dbfull()->CompactRange(CompactRangeOptions(), handles_[1], nullptr,
nullptr);
// We have only one valid snapshot snapshot2. Since snapshot1 is static std::vector<int> GenerateOptionConfigs() {
// not valid anymore, "first" should be removed by a compaction. std::vector<int> option_configs;
ASSERT_EQ("sixth", Get(1, "foo")); for (int option_config = kDefault; option_config < kEnd; ++option_config) {
ASSERT_EQ("fourth", Get(1, "foo", snapshot2)); if (!ShouldSkipOptions(option_config, kSkipFIFOCompaction)) {
ASSERT_EQ(AllEntriesFor("foo", 1), "[ sixth, fourth ]"); option_configs.push_back(option_config);
}
}
return option_configs;
}
};
// after we release the snapshot2, only one value should be left TEST_P(DBBasicMultiConfigs, CompactBetweenSnapshots) {
db_->ReleaseSnapshot(snapshot2); anon::OptionsOverride options_override;
FillLevels("a", "z", 1); options_override.skip_policy = kSkipNoSnapshot;
dbfull()->CompactRange(CompactRangeOptions(), handles_[1], nullptr, Options options = CurrentOptions(options_override);
nullptr); options.disable_auto_compactions = true;
ASSERT_EQ("sixth", Get(1, "foo")); DestroyAndReopen(options);
ASSERT_EQ(AllEntriesFor("foo", 1), "[ sixth ]"); CreateAndReopenWithCF({"pikachu"}, options);
} while (ChangeOptions(kSkipFIFOCompaction)); Random rnd(301);
FillLevels("a", "z", 1);
Put(1, "foo", "first");
const Snapshot* snapshot1 = db_->GetSnapshot();
Put(1, "foo", "second");
Put(1, "foo", "third");
Put(1, "foo", "fourth");
const Snapshot* snapshot2 = db_->GetSnapshot();
Put(1, "foo", "fifth");
Put(1, "foo", "sixth");
// All entries (including duplicates) exist
// before any compaction or flush is triggered.
ASSERT_EQ(AllEntriesFor("foo", 1),
"[ sixth, fifth, fourth, third, second, first ]");
ASSERT_EQ("sixth", Get(1, "foo"));
ASSERT_EQ("fourth", Get(1, "foo", snapshot2));
ASSERT_EQ("first", Get(1, "foo", snapshot1));
// After a flush, "second", "third" and "fifth" should
// be removed
ASSERT_OK(Flush(1));
ASSERT_EQ(AllEntriesFor("foo", 1), "[ sixth, fourth, first ]");
// after we release the snapshot1, only two values left
db_->ReleaseSnapshot(snapshot1);
FillLevels("a", "z", 1);
dbfull()->CompactRange(CompactRangeOptions(), handles_[1], nullptr, nullptr);
// We have only one valid snapshot snapshot2. Since snapshot1 is
// not valid anymore, "first" should be removed by a compaction.
ASSERT_EQ("sixth", Get(1, "foo"));
ASSERT_EQ("fourth", Get(1, "foo", snapshot2));
ASSERT_EQ(AllEntriesFor("foo", 1), "[ sixth, fourth ]");
// after we release the snapshot2, only one value should be left
db_->ReleaseSnapshot(snapshot2);
FillLevels("a", "z", 1);
dbfull()->CompactRange(CompactRangeOptions(), handles_[1], nullptr, nullptr);
ASSERT_EQ("sixth", Get(1, "foo"));
ASSERT_EQ(AllEntriesFor("foo", 1), "[ sixth ]");
} }
INSTANTIATE_TEST_CASE_P(
DBBasicMultiConfigs, DBBasicMultiConfigs,
::testing::ValuesIn(DBBasicMultiConfigs::GenerateOptionConfigs()));
TEST_F(DBBasicTest, DBOpen_Options) { TEST_F(DBBasicTest, DBOpen_Options) {
Options options = CurrentOptions(); Options options = CurrentOptions();
Close(); Close();

Loading…
Cancel
Save