Skip to content

Commit

Permalink
Fix a minor data race in stats dumping threads initialization (facebo…
Browse files Browse the repository at this point in the history
…ok#7151)

Summary:
facebook#7145 creates a minor data race against the stat creation counter. Turn it to atomic.

Pull Request resolved: facebook#7151

Test Plan: Run the test.

Reviewed By: ajkr

Differential Revision: D22631014

fbshipit-source-id: c6fb69ac5b9df7139795dacea5ce9fb9fd3278d7
  • Loading branch information
siying authored and facebook-github-bot committed Jul 20, 2020
1 parent 77062cf commit 9870704
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,13 @@ void DBImpl::StartTimedTasks() {
// threads dumping at once, which causes severe lock contention in
// jemalloc. Ensure successive `DB::Open()`s are staggered by at least
// one second in the common case.
static uint64_t stats_dump_threads_started = 0;
static std::atomic<uint64_t> stats_dump_threads_started(0);
thread_dump_stats_.reset(new ROCKSDB_NAMESPACE::RepeatableThread(
[this]() { DBImpl::DumpStats(); }, "dump_st", env_,
static_cast<uint64_t>(stats_dump_period_sec) * kMicrosInSecond,
stats_dump_threads_started %
stats_dump_threads_started.fetch_add(1) %
static_cast<uint64_t>(stats_dump_period_sec) *
kMicrosInSecond));
++stats_dump_threads_started;
}
}
stats_persist_period_sec = mutable_db_options_.stats_persist_period_sec;
Expand Down Expand Up @@ -1097,15 +1096,14 @@ Status DBImpl::SetDBOptions(
// severe lock contention in jemalloc. Ensure successive enabling of
// `stats_dump_period_sec` are staggered by at least one second in the
// common case.
static uint64_t stats_dump_threads_started = 0;
static std::atomic<uint64_t> stats_dump_threads_started(0);
thread_dump_stats_.reset(new ROCKSDB_NAMESPACE::RepeatableThread(
[this]() { DBImpl::DumpStats(); }, "dump_st", env_,
static_cast<uint64_t>(new_options.stats_dump_period_sec) *
kMicrosInSecond,
stats_dump_threads_started %
stats_dump_threads_started.fetch_add(1) %
static_cast<uint64_t>(new_options.stats_dump_period_sec) *
kMicrosInSecond));
++stats_dump_threads_started;
} else {
thread_dump_stats_.reset();
}
Expand Down

0 comments on commit 9870704

Please sign in to comment.