DBTest.DynamicCompactionOptions: More deterministic and readable

Summary: DBTest.DynamicCompactionOptions sometimes fails the assert but I can't repro it locally. Make it more deterministic and readable and see whether the problem is still there.

Test Plan: Run tht test and make sure it passes

Reviewers: kradhakrishnan, yhchiang, igor, rven, IslamAbdelRahman, anthony

Reviewed By: anthony

Subscribers: leveldb, dhruba

Differential Revision: https://reviews.facebook.net/D51309
This commit is contained in:
sdong 2015-11-25 15:43:11 -08:00
parent 0ad68518bb
commit f9103d9a30
2 changed files with 15 additions and 14 deletions

View File

@ -314,6 +314,10 @@ class DBImpl : public DB {
Cache* TEST_table_cache() { return table_cache_.get(); } Cache* TEST_table_cache() { return table_cache_.get(); }
const WriteController& TEST_write_controler() const {
return write_controller_;
}
#endif // NDEBUG #endif // NDEBUG
// Returns the list of live files in 'live' and the list // Returns the list of live files in 'live' and the list

View File

@ -7693,28 +7693,25 @@ TEST_F(DBTest, DynamicCompactionOptions) {
// Clean up memtable and L0. Block compaction threads. If continue to write // Clean up memtable and L0. Block compaction threads. If continue to write
// and flush memtables. We should see put stop after 8 memtable flushes // and flush memtables. We should see put stop after 8 memtable flushes
// since level0_stop_writes_trigger = 8 // since level0_stop_writes_trigger = 8
dbfull()->TEST_FlushMemTable(true);
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr);
// Block compaction // Block compaction
test::SleepingBackgroundTask sleeping_task_low; test::SleepingBackgroundTask sleeping_task_low;
env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task_low, env_->Schedule(&test::SleepingBackgroundTask::DoSleepTask, &sleeping_task_low,
Env::Priority::LOW); Env::Priority::LOW);
rocksdb::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::DelayWrite:Wait",
[&](void* arg) { sleeping_task_low.WakeUp(); });
rocksdb::SyncPoint::GetInstance()->EnableProcessing();
ASSERT_EQ(NumTableFilesAtLevel(0), 0); ASSERT_EQ(NumTableFilesAtLevel(0), 0);
int count = 0; int count = 0;
Random rnd(301); Random rnd(301);
WriteOptions wo; WriteOptions wo;
while (count < 64) { while (count < 64) {
ASSERT_OK(Put(Key(count), RandomString(&rnd, 1024), wo)); ASSERT_OK(Put(Key(count), RandomString(&rnd, 1024), wo));
if (sleeping_task_low.WokenUp()) {
break;
}
dbfull()->TEST_FlushMemTable(true); dbfull()->TEST_FlushMemTable(true);
count++; count++;
if (dbfull()->TEST_write_controler().IsStopped()) {
sleeping_task_low.WakeUp();
break;
}
} }
// Stop trigger = 8 // Stop trigger = 8
ASSERT_EQ(count, 8); ASSERT_EQ(count, 8);
@ -7727,6 +7724,7 @@ TEST_F(DBTest, DynamicCompactionOptions) {
ASSERT_OK(dbfull()->SetOptions({ ASSERT_OK(dbfull()->SetOptions({
{"level0_stop_writes_trigger", "6"} {"level0_stop_writes_trigger", "6"}
})); }));
dbfull()->TEST_FlushMemTable(true);
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr);
ASSERT_EQ(NumTableFilesAtLevel(0), 0); ASSERT_EQ(NumTableFilesAtLevel(0), 0);
@ -7737,11 +7735,12 @@ TEST_F(DBTest, DynamicCompactionOptions) {
count = 0; count = 0;
while (count < 64) { while (count < 64) {
ASSERT_OK(Put(Key(count), RandomString(&rnd, 1024), wo)); ASSERT_OK(Put(Key(count), RandomString(&rnd, 1024), wo));
if (sleeping_task_low.WokenUp()) {
break;
}
dbfull()->TEST_FlushMemTable(true); dbfull()->TEST_FlushMemTable(true);
count++; count++;
if (dbfull()->TEST_write_controler().IsStopped()) {
sleeping_task_low.WakeUp();
break;
}
} }
ASSERT_EQ(count, 6); ASSERT_EQ(count, 6);
// Unblock // Unblock
@ -7781,8 +7780,6 @@ TEST_F(DBTest, DynamicCompactionOptions) {
} }
dbfull()->TEST_WaitForCompact(); dbfull()->TEST_WaitForCompact();
ASSERT_LT(NumTableFilesAtLevel(0), 4); ASSERT_LT(NumTableFilesAtLevel(0), 4);
rocksdb::SyncPoint::GetInstance()->DisableProcessing();
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE
@ -10658,7 +10655,7 @@ TEST_P(BloomStatsTestWithParam, BloomStatsTestWithIter) {
iter.reset(dbfull()->NewIterator(ReadOptions())); iter.reset(dbfull()->NewIterator(ReadOptions()));
// check SST bloom stats // Check SST bloom stats
iter->Seek(key1); iter->Seek(key1);
ASSERT_OK(iter->status()); ASSERT_OK(iter->status());
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());