From 2243030bc5504cfa44267382ccb6df3bc029e057 Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Fri, 31 Jan 2020 10:26:58 -0800 Subject: [PATCH] Cancel bg jobs before deleting WritePrepared DB in stress tests (#6355) Summary: Background jobs in WritePrepared DB might access the db via a snapshot checker callback. The stress tests therefore should cancel background jobs before deleting the db in ::Reopen. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6355 Differential Revision: D19664132 Pulled By: maysamyabandeh fbshipit-source-id: 6060a830e8aad0015c10448286ad37c8a346ac01 --- db_stress_tool/db_stress_test_base.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 0d3b29409..925bb640e 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -2073,12 +2073,18 @@ void StressTest::Open() { void StressTest::Reopen(ThreadState* thread) { #ifndef ROCKSDB_LITE + // BG jobs in WritePrepared must be canceled first because i) they can access + // the db via a callbac ii) they hold on to a snapshot and the upcoming + // ::Close would complain about it. + const bool write_prepared = FLAGS_use_txn && FLAGS_txn_write_policy != 0; bool bg_canceled = false; - if (thread->rand.OneIn(2)) { - const bool wait = static_cast(thread->rand.OneIn(2)); + if (write_prepared || thread->rand.OneIn(2)) { + const bool wait = + write_prepared || static_cast(thread->rand.OneIn(2)); CancelAllBackgroundWork(db_, wait); bg_canceled = wait; } + assert(!write_prepared || bg_canceled); #else (void) thread; #endif @@ -2089,9 +2095,7 @@ void StressTest::Reopen(ThreadState* thread) { column_families_.clear(); #ifndef ROCKSDB_LITE - // BG jobs in WritePrepared hold on to a snapshot - const bool write_prepared = FLAGS_use_txn && FLAGS_txn_write_policy != 0; - if (thread->rand.OneIn(2) && (!write_prepared || bg_canceled)) { + if (thread->rand.OneIn(2)) { Status s = db_->Close(); if (!s.ok()) { fprintf(stderr, "Non-ok close status: %s\n", s.ToString().c_str()); -- GitLab