提交 ef15b9d1 编写于 作者: H Haobo Xu

[RocksDB] Fix MaybeDumpStats

Summary: MaybeDumpStats was causing lock problem

Test Plan: make check; db_stress

Reviewers: dhruba

Reviewed By: dhruba

Differential Revision: https://reviews.facebook.net/D10935
上级 0e879c93
...@@ -305,20 +305,21 @@ const Status DBImpl::CreateArchivalDirectory() { ...@@ -305,20 +305,21 @@ const Status DBImpl::CreateArchivalDirectory() {
} }
void DBImpl::MaybeDumpStats() { void DBImpl::MaybeDumpStats() {
mutex_.AssertHeld(); if (options_.stats_dump_period_sec == 0) return;
if (options_.stats_dump_period_sec != 0) {
const uint64_t now_micros = env_->NowMicros(); const uint64_t now_micros = env_->NowMicros();
if (last_stats_dump_time_microsec_ + if (last_stats_dump_time_microsec_ +
options_.stats_dump_period_sec * 1000000 options_.stats_dump_period_sec * 1000000
<= now_micros) { <= now_micros) {
// Multiple threads could race in here simultaneously.
// However, the last one will update last_stats_dump_time_microsec_
// atomically. We could see more than one dump during one dump
// period in rare cases.
last_stats_dump_time_microsec_ = now_micros; last_stats_dump_time_microsec_ = now_micros;
mutex_.Unlock();
std::string stats; std::string stats;
GetProperty("leveldb.stats", &stats); GetProperty("leveldb.stats", &stats);
Log(options_.info_log, "%s", stats.c_str()); Log(options_.info_log, "%s", stats.c_str());
mutex_.Lock();
}
} }
} }
...@@ -1233,6 +1234,9 @@ void DBImpl::TEST_PurgeObsoleteteWAL() { ...@@ -1233,6 +1234,9 @@ void DBImpl::TEST_PurgeObsoleteteWAL() {
void DBImpl::BackgroundCall() { void DBImpl::BackgroundCall() {
bool madeProgress = false; bool madeProgress = false;
DeletionState deletion_state; DeletionState deletion_state;
MaybeDumpStats();
MutexLock l(&mutex_); MutexLock l(&mutex_);
// Log(options_.info_log, "XXX BG Thread %llx process new work item", pthread_self()); // Log(options_.info_log, "XXX BG Thread %llx process new work item", pthread_self());
assert(bg_compaction_scheduled_); assert(bg_compaction_scheduled_);
...@@ -1273,7 +1277,6 @@ void DBImpl::BackgroundCall() { ...@@ -1273,7 +1277,6 @@ void DBImpl::BackgroundCall() {
} }
bg_cv_.SignalAll(); bg_cv_.SignalAll();
MaybeDumpStats();
} }
Status DBImpl::BackgroundCompaction(bool* madeProgress, Status DBImpl::BackgroundCompaction(bool* madeProgress,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef STORAGE_LEVELDB_DB_DB_IMPL_H_ #ifndef STORAGE_LEVELDB_DB_DB_IMPL_H_
#define STORAGE_LEVELDB_DB_DB_IMPL_H_ #define STORAGE_LEVELDB_DB_DB_IMPL_H_
#include <atomic>
#include <deque> #include <deque>
#include <set> #include <set>
#include "db/dbformat.h" #include "db/dbformat.h"
...@@ -277,7 +278,7 @@ class DBImpl : public DB { ...@@ -277,7 +278,7 @@ class DBImpl : public DB {
uint64_t purge_wal_files_last_run_; uint64_t purge_wal_files_last_run_;
// last time stats were dumped to LOG // last time stats were dumped to LOG
uint64_t last_stats_dump_time_microsec_; std::atomic<uint64_t> last_stats_dump_time_microsec_;
// These count the number of microseconds for which MakeRoomForWrite stalls. // These count the number of microseconds for which MakeRoomForWrite stalls.
uint64_t stall_level0_slowdown_; uint64_t stall_level0_slowdown_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册