Fix flaky db_basic_bench caused by unreleased iterator (#10058)

Summary:
Iterator is not freed after test is done (after the main for
loop), which could cause db close failed.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10058

Test Plan:
Able to reproduce consistently with higher thread number,
like 100, make sure it passes after the fix

Reviewed By: ajkr

Differential Revision: D36685823

Pulled By: jay-zhuang

fbshipit-source-id: 4c98b8758d106bfe40cae670e689c3d284765bcf
main
Jay Zhuang 3 years ago committed by Facebook GitHub Bot
parent bd170dda03
commit 5490da20a5
  1. 26
      microbench/db_basic_bench.cc

@ -1109,9 +1109,8 @@ static void IteratorSeek(benchmark::State& state) {
} }
} }
{
std::unique_ptr<Iterator> iter{nullptr};
for (auto _ : state) { for (auto _ : state) {
std::unique_ptr<Iterator> iter{nullptr};
state.PauseTiming(); state.PauseTiming();
if (!iter) { if (!iter) {
iter.reset(db->NewIterator(ReadOptions())); iter.reset(db->NewIterator(ReadOptions()));
@ -1124,7 +1123,6 @@ static void IteratorSeek(benchmark::State& state) {
state.ResumeTiming(); state.ResumeTiming();
iter->Seek(key); iter->Seek(key);
} }
}
if (state.thread_index() == 0) { if (state.thread_index() == 0) {
TeardownDB(state, db, options, kg); TeardownDB(state, db, options, kg);
@ -1202,9 +1200,8 @@ static void IteratorNext(benchmark::State& state) {
} }
} }
{
std::unique_ptr<Iterator> iter{nullptr};
for (auto _ : state) { for (auto _ : state) {
std::unique_ptr<Iterator> iter{nullptr};
state.PauseTiming(); state.PauseTiming();
if (!iter) { if (!iter) {
iter.reset(db->NewIterator(ReadOptions())); iter.reset(db->NewIterator(ReadOptions()));
@ -1218,7 +1215,6 @@ static void IteratorNext(benchmark::State& state) {
state.ResumeTiming(); state.ResumeTiming();
iter->Next(); iter->Next();
} }
}
if (state.thread_index() == 0) { if (state.thread_index() == 0) {
TeardownDB(state, db, options, kg); TeardownDB(state, db, options, kg);
@ -1281,9 +1277,8 @@ static void IteratorNextWithPerfContext(benchmark::State& state) {
SetPerfLevel(kEnableTime); SetPerfLevel(kEnableTime);
get_perf_context()->EnablePerLevelPerfContext(); get_perf_context()->EnablePerLevelPerfContext();
{
std::unique_ptr<Iterator> iter{nullptr};
for (auto _ : state) { for (auto _ : state) {
std::unique_ptr<Iterator> iter{nullptr};
state.PauseTiming(); state.PauseTiming();
if (!iter) { if (!iter) {
iter.reset(db->NewIterator(ReadOptions())); iter.reset(db->NewIterator(ReadOptions()));
@ -1298,15 +1293,12 @@ static void IteratorNextWithPerfContext(benchmark::State& state) {
state.ResumeTiming(); state.ResumeTiming();
iter->Next(); iter->Next();
user_key_comparison_count += user_key_comparison_count += get_perf_context()->user_key_comparison_count;
get_perf_context()->user_key_comparison_count;
internal_key_skipped_count += internal_key_skipped_count +=
get_perf_context()->internal_key_skipped_count; get_perf_context()->internal_key_skipped_count;
find_next_user_entry_time += find_next_user_entry_time += get_perf_context()->find_next_user_entry_time;
get_perf_context()->find_next_user_entry_time;
iter_next_cpu_nanos += get_perf_context()->iter_next_cpu_nanos; iter_next_cpu_nanos += get_perf_context()->iter_next_cpu_nanos;
} }
}
state.counters["user_key_comparison_count"] = state.counters["user_key_comparison_count"] =
benchmark::Counter(static_cast<double>(user_key_comparison_count), benchmark::Counter(static_cast<double>(user_key_comparison_count),
@ -1370,9 +1362,8 @@ static void IteratorPrev(benchmark::State& state) {
} }
} }
{
std::unique_ptr<Iterator> iter{nullptr};
for (auto _ : state) { for (auto _ : state) {
std::unique_ptr<Iterator> iter{nullptr};
state.PauseTiming(); state.PauseTiming();
if (!iter) { if (!iter) {
iter.reset(db->NewIterator(ReadOptions())); iter.reset(db->NewIterator(ReadOptions()));
@ -1386,7 +1377,6 @@ static void IteratorPrev(benchmark::State& state) {
state.ResumeTiming(); state.ResumeTiming();
iter->Prev(); iter->Prev();
} }
}
if (state.thread_index() == 0) { if (state.thread_index() == 0) {
TeardownDB(state, db, options, kg); TeardownDB(state, db, options, kg);
@ -1464,9 +1454,8 @@ static void PrefixSeek(benchmark::State& state) {
} }
} }
{
std::unique_ptr<Iterator> iter{nullptr};
for (auto _ : state) { for (auto _ : state) {
std::unique_ptr<Iterator> iter{nullptr};
state.PauseTiming(); state.PauseTiming();
if (!iter) { if (!iter) {
iter.reset(db->NewIterator(ReadOptions())); iter.reset(db->NewIterator(ReadOptions()));
@ -1478,7 +1467,6 @@ static void PrefixSeek(benchmark::State& state) {
return; return;
} }
} }
}
if (state.thread_index() == 0) { if (state.thread_index() == 0) {
TeardownDB(state, db, options, kg); TeardownDB(state, db, options, kg);

Loading…
Cancel
Save