db_bench seekrandom with multiDB should only create iterators queried (#7818)
Summary: Right now, db_bench with seekrandom and multiple DB setup creates iterator for all DBs just to query one of them. It's different from most real workloads. Fix it by only creating iterators that will be queried. Also fix a bug that DBs are not destroyed in multi-DB mode. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7818 Test Plan: Run db_bench with single/multiDB X using/not using tailing iterator with ASAN build, and validate the behavior is expected. Reviewed By: ajkr Differential Revision: D25720226 fbshipit-source-id: c2ff7ff7120e5ba64287a30b057c5d29b2cbe20b
This commit is contained in:
parent
0229a88dfe
commit
1e5b631e51
@ -3095,11 +3095,15 @@ class Benchmark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~Benchmark() {
|
void DeleteDBs() {
|
||||||
db_.DeleteDBs();
|
db_.DeleteDBs();
|
||||||
for (auto db : multi_dbs_) {
|
for (const DBWithColumnFamilies& dbwcf : multi_dbs_) {
|
||||||
db.DeleteDBs();
|
delete dbwcf.db;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~Benchmark() {
|
||||||
|
DeleteDBs();
|
||||||
delete prefix_extractor_;
|
delete prefix_extractor_;
|
||||||
if (cache_.get() != nullptr) {
|
if (cache_.get() != nullptr) {
|
||||||
// Clear cache reference first
|
// Clear cache reference first
|
||||||
@ -3232,10 +3236,7 @@ class Benchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ErrorExit() {
|
void ErrorExit() {
|
||||||
db_.DeleteDBs();
|
DeleteDBs();
|
||||||
for (size_t i = 0; i < multi_dbs_.size(); i++) {
|
|
||||||
delete multi_dbs_[i].db;
|
|
||||||
}
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6187,13 +6188,14 @@ class Benchmark {
|
|||||||
options.timestamp = &ts;
|
options.timestamp = &ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator* single_iter = nullptr;
|
std::vector<Iterator*> tailing_iters;
|
||||||
std::vector<Iterator*> multi_iters;
|
if (FLAGS_use_tailing_iterator) {
|
||||||
if (db_.db != nullptr) {
|
if (db_.db != nullptr) {
|
||||||
single_iter = db_.db->NewIterator(options);
|
tailing_iters.push_back(db_.db->NewIterator(options));
|
||||||
} else {
|
} else {
|
||||||
for (const auto& db_with_cfh : multi_dbs_) {
|
for (const auto& db_with_cfh : multi_dbs_) {
|
||||||
multi_iters.push_back(db_with_cfh.db->NewIterator(options));
|
tailing_iters.push_back(db_with_cfh.db->NewIterator(options));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6227,24 +6229,21 @@ class Benchmark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FLAGS_use_tailing_iterator) {
|
|
||||||
if (db_.db != nullptr) {
|
|
||||||
delete single_iter;
|
|
||||||
single_iter = db_.db->NewIterator(options);
|
|
||||||
} else {
|
|
||||||
for (auto iter : multi_iters) {
|
|
||||||
delete iter;
|
|
||||||
}
|
|
||||||
multi_iters.clear();
|
|
||||||
for (const auto& db_with_cfh : multi_dbs_) {
|
|
||||||
multi_iters.push_back(db_with_cfh.db->NewIterator(options));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Pick a Iterator to use
|
// Pick a Iterator to use
|
||||||
Iterator* iter_to_use = single_iter;
|
size_t cf_to_use = (db_.db == nullptr)
|
||||||
if (single_iter == nullptr) {
|
? (size_t{thread->rand.Next()} % multi_dbs_.size())
|
||||||
iter_to_use = multi_iters[thread->rand.Next() % multi_iters.size()];
|
: 0;
|
||||||
|
std::unique_ptr<Iterator> single_iter;
|
||||||
|
Iterator* iter_to_use;
|
||||||
|
if (FLAGS_use_tailing_iterator) {
|
||||||
|
iter_to_use = tailing_iters[cf_to_use];
|
||||||
|
} else {
|
||||||
|
if (db_.db != nullptr) {
|
||||||
|
single_iter.reset(db_.db->NewIterator(options));
|
||||||
|
} else {
|
||||||
|
single_iter.reset(multi_dbs_[cf_to_use].db->NewIterator(options));
|
||||||
|
}
|
||||||
|
iter_to_use = single_iter.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
iter_to_use->Seek(key);
|
iter_to_use->Seek(key);
|
||||||
@ -6276,8 +6275,7 @@ class Benchmark {
|
|||||||
|
|
||||||
thread->stats.FinishedOps(&db_, db_.db, 1, kSeek);
|
thread->stats.FinishedOps(&db_, db_.db, 1, kSeek);
|
||||||
}
|
}
|
||||||
delete single_iter;
|
for (auto iter : tailing_iters) {
|
||||||
for (auto iter : multi_iters) {
|
|
||||||
delete iter;
|
delete iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user