Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 3869 #3894

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/common/stats/StatsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,18 @@ void StatsManager::addValue(const CounterId& id, VT value) {
bool isHisto = id.isHisto();
if (!isHisto) {
// Stats
DCHECK(sm.stats_.find(index) != sm.stats_.end());
std::lock_guard<std::mutex> g(*(sm.stats_[index].first));
sm.stats_[index].second->addValue(seconds(time::WallClock::fastNowInSec()), value);
auto iter = sm.stats_.find(index);
if (iter != sm.stats_.end()) {
std::lock_guard<std::mutex> g(*(iter->second.first));
iter->second.second->addValue(seconds(time::WallClock::fastNowInSec()), value);
}
} else {
// Histogram
DCHECK(sm.histograms_.find(index) != sm.histograms_.end());
std::lock_guard<std::mutex> g(*(sm.histograms_[index].first));
sm.histograms_[index].second->addValue(seconds(time::WallClock::fastNowInSec()), value);
auto iter = sm.histograms_.find(index);
if (iter != sm.histograms_.end()) {
std::lock_guard<std::mutex> g(*(iter->second.first));
iter->second.second->addValue(seconds(time::WallClock::fastNowInSec()), value);
}
}
}

Expand Down Expand Up @@ -464,16 +468,18 @@ StatusOr<StatsManager::VT> StatsManager::readStats(const CounterId& id,

if (!id.isHisto()) {
// stats
DCHECK(sm.stats_.find(index) != sm.stats_.end());
std::lock_guard<std::mutex> g(*(sm.stats_[index].first));
sm.stats_[index].second->update(seconds(time::WallClock::fastNowInSec()));
return readValue(*(sm.stats_[index].second), range, method);
auto iter = sm.stats_.find(index);
DCHECK(iter != sm.stats_.end());
std::lock_guard<std::mutex> g(*(iter->second.first));
iter->second.second->update(seconds(time::WallClock::fastNowInSec()));
return readValue(*(iter->second.second), range, method);
} else {
// histograms_
DCHECK(sm.histograms_.find(index) != sm.histograms_.end());
std::lock_guard<std::mutex> g(*(sm.histograms_[index].first));
sm.histograms_[index].second->update(seconds(time::WallClock::fastNowInSec()));
return readValue(*(sm.histograms_[index].second), range, method);
auto iter = sm.histograms_.find(index);
DCHECK(iter != sm.histograms_.end());
std::lock_guard<std::mutex> g(*(iter->second.first));
iter->second.second->update(seconds(time::WallClock::fastNowInSec()));
return readValue(*(iter->second.second), range, method);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/common/stats/StatsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define COMMON_STATS_STATSMANAGER_H_

#include <folly/RWSpinLock.h>
#include <folly/concurrency/ConcurrentHashMap.h>
#include <folly/stats/MultiLevelTimeSeries.h>
#include <folly/stats/TimeseriesHistogram.h>

Expand Down Expand Up @@ -206,8 +207,8 @@ class StatsManager final {
std::unordered_map<std::string, CounterInfo> nameMap_;

// All time series stats
std::unordered_map<std::string,
std::pair<std::unique_ptr<std::mutex>, std::unique_ptr<StatsType>>>
folly::ConcurrentHashMap<std::string,
std::pair<std::unique_ptr<std::mutex>, std::unique_ptr<StatsType>>>
stats_;

// All histogram stats
Expand Down