From 7a99162a749da0dc3f79a945ff1ce069b95b548a Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 10 Dec 2019 20:01:25 -0800 Subject: [PATCH] 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 --- db_stress_tool/db_stress_test_base.cc | 20 ++++++++++++++++++-- db_stress_tool/db_stress_test_base.h | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 2fa150dc8c..cf6346efb5 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -11,6 +11,7 @@ #ifdef GFLAGS #include "db_stress_tool/db_stress_common.h" #include "db_stress_tool/db_stress_driver.h" +#include "rocksdb/convenience.h" namespace rocksdb { StressTest::StressTest() @@ -485,7 +486,7 @@ void StressTest::OperateDb(ThreadState* thread) { } thread->shared->IncVotedReopen(); if (thread->shared->AllVotedReopen()) { - thread->shared->GetStressTest()->Reopen(); + thread->shared->GetStressTest()->Reopen(thread); thread->shared->GetCondVar()->SignalAll(); } else { 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(thread->rand.OneIn(2))); + } +#else + (void) thread; +#endif + for (auto cf : column_families_) { delete cf; } column_families_.clear(); + +#ifndef ROCKSDB_LITE + if (thread->rand.OneIn(2)) { + Status s = db_->Close(); + assert(s.ok()); + } +#endif delete db_; db_ = nullptr; #ifndef ROCKSDB_LITE diff --git a/db_stress_tool/db_stress_test_base.h b/db_stress_tool/db_stress_test_base.h index 664fa57055..869405a679 100644 --- a/db_stress_tool/db_stress_test_base.h +++ b/db_stress_tool/db_stress_test_base.h @@ -171,7 +171,7 @@ class StressTest { void Open(); - void Reopen(); + void Reopen(ThreadState* thread); std::shared_ptr cache_; std::shared_ptr compressed_cache_;