From 58312c12abe60adcaf598ea5dc3e85a9d7ae4ff2 Mon Sep 17 00:00:00 2001 From: andy-byers Date: Wed, 18 Jan 2023 23:02:44 -0600 Subject: [PATCH] db_bench: fix for issue #290 Changed db_bench so that when using multiple databases (num_multi_db > 1) we only destroy databases that were used for the current group (databases specified in dbs_to_use). --- tools/db_bench_tool.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 803532d7fe..d4670ddd91 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -2941,7 +2941,6 @@ class Benchmark { } void OpenAllDbs(Options options) { - assert(dbs_.empty()); assert(FLAGS_num_multi_db > 0); // dbs_to_use_ is NOT initialized here since we open the db-s once for all @@ -2953,6 +2952,9 @@ class Benchmark { } else { auto wal_dir = options.wal_dir; for (int i = 0; i < FLAGS_num_multi_db; i++) { + if (dbs_[i].db || dbs_[i].opt_txn_db) { + continue; + } if (!wal_dir.empty()) { options.wal_dir = GetPathForMultiple(wal_dir, i); } @@ -2962,17 +2964,17 @@ class Benchmark { } } - void DestroyAllDbs() { - // Record the number of db-s as dbs_ is cleared inside DeleteDBs() - auto num_dbs = dbs_.size(); - - DeleteDBs(); + void DestroyUsedDbs() { + for (auto i : db_idxs_to_use) { + dbs_[i].DeleteDBs(); + } + dbs_to_use_.clear(); - if (num_dbs == 1U) { + if (IsSingleDb()) { DestroyDB(FLAGS_db, open_options_); - } else if (num_dbs > 1U) { + } else if (IsMultiDb()) { Options options = open_options_; - for (auto i = 0U; i < num_dbs; ++i) { + for (auto i : db_idxs_to_use) { if (!open_options_.wal_dir.empty()) { options.wal_dir = GetPathForMultiple(open_options_.wal_dir, i); } @@ -4006,7 +4008,7 @@ class Benchmark { "--use_existing_db", name.c_str()); } else { - DestroyAllDbs(); + DestroyUsedDbs(); Open(&open_options_); // use open_options for the last accessed // There are new DB-s => Re-initialize dbs_to_use_ InitDbsToUse();