db_stress: sometimes call CancelAllBackgroundWork() and Close() before closing DB (#6141)

Summary:
CancelAllBackgroundWork() and Close() are frequently used features but we don't cover it in stress test. Simply execute them before closing the DB with 1/2 chance.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6141

Test Plan: Run "db_stress".

Differential Revision: D18900861

fbshipit-source-id: 49b46ccfae120d0f9de3e0543b82fb6d715949d0
This commit is contained in:
sdong 2019-12-10 20:01:25 -08:00 committed by Facebook Github Bot
parent 984b6e71d6
commit 7a99162a74
2 changed files with 19 additions and 3 deletions

View File

@ -11,6 +11,7 @@
#ifdef GFLAGS #ifdef GFLAGS
#include "db_stress_tool/db_stress_common.h" #include "db_stress_tool/db_stress_common.h"
#include "db_stress_tool/db_stress_driver.h" #include "db_stress_tool/db_stress_driver.h"
#include "rocksdb/convenience.h"
namespace rocksdb { namespace rocksdb {
StressTest::StressTest() StressTest::StressTest()
@ -485,7 +486,7 @@ void StressTest::OperateDb(ThreadState* thread) {
} }
thread->shared->IncVotedReopen(); thread->shared->IncVotedReopen();
if (thread->shared->AllVotedReopen()) { if (thread->shared->AllVotedReopen()) {
thread->shared->GetStressTest()->Reopen(); thread->shared->GetStressTest()->Reopen(thread);
thread->shared->GetCondVar()->SignalAll(); thread->shared->GetCondVar()->SignalAll();
} else { } else {
thread->shared->GetCondVar()->Wait(); thread->shared->GetCondVar()->Wait();
@ -1746,11 +1747,26 @@ void StressTest::Open() {
} }
} }
void StressTest::Reopen() { void StressTest::Reopen(ThreadState* thread) {
#ifndef ROCKSDB_LITE
if (thread->rand.OneIn(2)) {
CancelAllBackgroundWork(db_, static_cast<bool>(thread->rand.OneIn(2)));
}
#else
(void) thread;
#endif
for (auto cf : column_families_) { for (auto cf : column_families_) {
delete cf; delete cf;
} }
column_families_.clear(); column_families_.clear();
#ifndef ROCKSDB_LITE
if (thread->rand.OneIn(2)) {
Status s = db_->Close();
assert(s.ok());
}
#endif
delete db_; delete db_;
db_ = nullptr; db_ = nullptr;
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE

View File

@ -171,7 +171,7 @@ class StressTest {
void Open(); void Open();
void Reopen(); void Reopen(ThreadState* thread);
std::shared_ptr<Cache> cache_; std::shared_ptr<Cache> cache_;
std::shared_ptr<Cache> compressed_cache_; std::shared_ptr<Cache> compressed_cache_;