Unverified Commit f963b880 authored by Connor's avatar Connor Committed by GitHub

support histogram for titan stats (#74)

Signed-off-by: 's avatarConnor1996 <zbk602423539@gmail.com>
parent 73ed3a9f
...@@ -56,7 +56,7 @@ class TitanDBImpl::FileManager : public BlobFileManager { ...@@ -56,7 +56,7 @@ class TitanDBImpl::FileManager : public BlobFileManager {
VersionEdit edit; VersionEdit edit;
edit.SetColumnFamilyID(cf_id); edit.SetColumnFamilyID(cf_id);
for (auto& file : files) { for (auto& file : files) {
RecordTick(statistics(db_->stats_.get()), BLOB_DB_BLOB_FILE_SYNCED); RecordTick(db_->stats_.get(), BLOB_DB_BLOB_FILE_SYNCED);
{ {
StopWatch sync_sw(db_->env_, statistics(db_->stats_.get()), StopWatch sync_sw(db_->env_, statistics(db_->stats_.get()),
BLOB_DB_BLOB_FILE_SYNC_MICROS); BLOB_DB_BLOB_FILE_SYNC_MICROS);
...@@ -278,7 +278,7 @@ Status TitanDBImpl::Open(const std::vector<TitanCFDescriptor>& descs, ...@@ -278,7 +278,7 @@ Status TitanDBImpl::Open(const std::vector<TitanCFDescriptor>& descs,
if (s.ok()) { if (s.ok()) {
db_impl_ = reinterpret_cast<DBImpl*>(db_->GetRootDB()); db_impl_ = reinterpret_cast<DBImpl*>(db_->GetRootDB());
if (stats_.get()) { if (stats_.get()) {
stats_->Initialize(column_families, db_->DefaultColumnFamily()->GetID()); stats_->Initialize(column_families);
} }
ROCKS_LOG_INFO(db_options_.info_log, "Titan DB open."); ROCKS_LOG_INFO(db_options_.info_log, "Titan DB open.");
ROCKS_LOG_HEADER(db_options_.info_log, "Titan git sha: %s", ROCKS_LOG_HEADER(db_options_.info_log, "Titan git sha: %s",
...@@ -555,8 +555,8 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options, ...@@ -555,8 +555,8 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
StopWatch read_sw(env_, statistics(stats_.get()), StopWatch read_sw(env_, statistics(stats_.get()),
BLOB_DB_BLOB_FILE_READ_MICROS); BLOB_DB_BLOB_FILE_READ_MICROS);
s = storage->Get(options, index, &record, &buffer); s = storage->Get(options, index, &record, &buffer);
RecordTick(statistics(stats_.get()), BLOB_DB_NUM_KEYS_READ); RecordTick(stats_.get(), BLOB_DB_NUM_KEYS_READ);
RecordTick(statistics(stats_.get()), BLOB_DB_BLOB_FILE_BYTES_READ, RecordTick(stats_.get(), BLOB_DB_BLOB_FILE_BYTES_READ,
index.blob_handle.size); index.blob_handle.size);
} }
if (s.IsCorruption()) { if (s.IsCorruption()) {
......
...@@ -26,8 +26,8 @@ const std::string TitanDB::Properties::kLiveBlobFileSize = ...@@ -26,8 +26,8 @@ const std::string TitanDB::Properties::kLiveBlobFileSize =
const std::string TitanDB::Properties::kObsoleteBlobFileSize = const std::string TitanDB::Properties::kObsoleteBlobFileSize =
titandb_prefix + obsolete_blob_file_size; titandb_prefix + obsolete_blob_file_size;
const std::unordered_map<std::string, TitanInternalStats::StatsType> const std::unordered_map<std::string, TitanInternalStats::TickerType>
TitanInternalStats::stats_type_string_map = { TitanInternalStats::ticker_type_string_map = {
{TitanDB::Properties::kLiveBlobSize, {TitanDB::Properties::kLiveBlobSize,
TitanInternalStats::LIVE_BLOB_SIZE}, TitanInternalStats::LIVE_BLOB_SIZE},
{TitanDB::Properties::kNumLiveBlobFile, {TitanDB::Properties::kNumLiveBlobFile,
...@@ -40,6 +40,9 @@ const std::unordered_map<std::string, TitanInternalStats::StatsType> ...@@ -40,6 +40,9 @@ const std::unordered_map<std::string, TitanInternalStats::StatsType>
TitanInternalStats::OBSOLETE_BLOB_FILE_SIZE}, TitanInternalStats::OBSOLETE_BLOB_FILE_SIZE},
}; };
const std::unordered_map<std::string, TitanInternalStats::HistogramType>
TitanInternalStats::histogram_type_string_map = {};
const std::array<std::string, const std::array<std::string,
static_cast<int>(InternalOpType::INTERNAL_OP_ENUM_MAX)> static_cast<int>(InternalOpType::INTERNAL_OP_ENUM_MAX)>
TitanInternalStats::internal_op_names = { TitanInternalStats::internal_op_names = {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <unordered_map> #include <unordered_map>
#include "logging/log_buffer.h" #include "logging/log_buffer.h"
#include "monitoring/histogram.h"
#include "rocksdb/iostats_context.h" #include "rocksdb/iostats_context.h"
#include "rocksdb/statistics.h" #include "rocksdb/statistics.h"
...@@ -47,21 +48,29 @@ using InternalOpStats = ...@@ -47,21 +48,29 @@ using InternalOpStats =
// data. // data.
class TitanInternalStats { class TitanInternalStats {
public: public:
enum StatsType { enum TickerType {
LIVE_BLOB_SIZE = 0, LIVE_BLOB_SIZE = 0,
NUM_LIVE_BLOB_FILE, NUM_LIVE_BLOB_FILE,
NUM_OBSOLETE_BLOB_FILE, NUM_OBSOLETE_BLOB_FILE,
LIVE_BLOB_FILE_SIZE, LIVE_BLOB_FILE_SIZE,
OBSOLETE_BLOB_FILE_SIZE, OBSOLETE_BLOB_FILE_SIZE,
INTERNAL_STATS_ENUM_MAX, INTERNAL_TICKER_ENUM_MAX,
};
enum HistogramType {
INTERNAL_HISTOGRAM_ENUM_MAX,
}; };
TitanInternalStats() { Clear(); } TitanInternalStats() { Clear(); }
void Clear() { void Clear() {
for (int stat = 0; stat < INTERNAL_STATS_ENUM_MAX; stat++) { for (int type = 0; type < INTERNAL_TICKER_ENUM_MAX; type++) {
stats_[stat].store(0, std::memory_order_relaxed); tickers_[type].store(0, std::memory_order_relaxed);
} }
for (int type = 0; type < INTERNAL_HISTOGRAM_ENUM_MAX; type++) {
histograms_[type].Clear();
}
for (int op = 0; for (int op = 0;
op < static_cast<int>(InternalOpType::INTERNAL_OP_ENUM_MAX); op++) { op < static_cast<int>(InternalOpType::INTERNAL_OP_ENUM_MAX); op++) {
assert( assert(
...@@ -76,24 +85,28 @@ class TitanInternalStats { ...@@ -76,24 +85,28 @@ class TitanInternalStats {
} }
} }
void ResetStats(StatsType type) { void ResetStats(TickerType type) {
stats_[type].store(0, std::memory_order_relaxed); tickers_[type].store(0, std::memory_order_relaxed);
} }
void AddStats(StatsType type, uint64_t value) { void AddStats(TickerType type, uint64_t value) {
auto& v = stats_[type]; auto& v = tickers_[type];
v.fetch_add(value, std::memory_order_relaxed); v.fetch_add(value, std::memory_order_relaxed);
} }
void SubStats(StatsType type, uint64_t value) { void SubStats(TickerType type, uint64_t value) {
auto& v = stats_[type]; auto& v = tickers_[type];
v.fetch_sub(value, std::memory_order_relaxed); v.fetch_sub(value, std::memory_order_relaxed);
} }
void MeasureTime(HistogramType type, uint64_t value) {
histograms_[type].Add(value);
}
bool GetIntProperty(const Slice& property, uint64_t* value) const { bool GetIntProperty(const Slice& property, uint64_t* value) const {
auto p = stats_type_string_map.find(property.ToString()); auto p = ticker_type_string_map.find(property.ToString());
if (p != stats_type_string_map.end()) { if (p != ticker_type_string_map.end()) {
*value = stats_[p->second].load(std::memory_order_relaxed); *value = tickers_[p->second].load(std::memory_order_relaxed);
return true; return true;
} }
return false; return false;
...@@ -115,15 +128,21 @@ class TitanInternalStats { ...@@ -115,15 +128,21 @@ class TitanInternalStats {
void DumpAndResetInternalOpStats(LogBuffer* log_buffer); void DumpAndResetInternalOpStats(LogBuffer* log_buffer);
private: private:
static const std::unordered_map<std::string, TitanInternalStats::StatsType>
stats_type_string_map;
static const std::array< static const std::array<
std::string, static_cast<int>(InternalOpType::INTERNAL_OP_ENUM_MAX)> std::string, static_cast<int>(InternalOpType::INTERNAL_OP_ENUM_MAX)>
internal_op_names; internal_op_names;
std::array<std::atomic<uint64_t>, INTERNAL_STATS_ENUM_MAX> stats_;
std::array<InternalOpStats, std::array<InternalOpStats,
static_cast<size_t>(InternalOpType::INTERNAL_OP_ENUM_MAX)> static_cast<size_t>(InternalOpType::INTERNAL_OP_ENUM_MAX)>
internal_op_stats_; internal_op_stats_;
static const std::unordered_map<std::string, TitanInternalStats::TickerType>
ticker_type_string_map;
std::array<std::atomic<uint64_t>, INTERNAL_TICKER_ENUM_MAX> tickers_;
static const std::unordered_map<std::string,
TitanInternalStats::HistogramType>
histogram_type_string_map;
std::array<HistogramImpl, INTERNAL_HISTOGRAM_ENUM_MAX> histograms_;
}; };
class TitanStats { class TitanStats {
...@@ -132,12 +151,10 @@ class TitanStats { ...@@ -132,12 +151,10 @@ class TitanStats {
// TODO: Initialize corresponding internal stats struct for Column families // TODO: Initialize corresponding internal stats struct for Column families
// created after DB open. // created after DB open.
Status Initialize(std::map<uint32_t, TitanCFOptions> cf_options, Status Initialize(std::map<uint32_t, TitanCFOptions> cf_options) {
uint32_t default_cf) {
for (auto& opts : cf_options) { for (auto& opts : cf_options) {
internal_stats_[opts.first] = NewTitanInternalStats(opts.second); internal_stats_[opts.first] = NewTitanInternalStats(opts.second);
} }
default_cf_ = default_cf;
return Status::OK(); return Status::OK();
} }
...@@ -155,8 +172,8 @@ class TitanStats { ...@@ -155,8 +172,8 @@ class TitanStats {
void DumpInternalOpStats(uint32_t cf_id, const std::string& cf_name); void DumpInternalOpStats(uint32_t cf_id, const std::string& cf_name);
private: private:
// RocksDB statistics
Statistics* stats_ = nullptr; Statistics* stats_ = nullptr;
uint32_t default_cf_ = 0;
std::unordered_map<uint32_t, std::shared_ptr<TitanInternalStats>> std::unordered_map<uint32_t, std::shared_ptr<TitanInternalStats>>
internal_stats_; internal_stats_;
std::shared_ptr<TitanInternalStats> NewTitanInternalStats( std::shared_ptr<TitanInternalStats> NewTitanInternalStats(
...@@ -165,7 +182,7 @@ class TitanStats { ...@@ -165,7 +182,7 @@ class TitanStats {
} }
}; };
// Utility functions // Utility functions for RocksDB stats types
inline Statistics* statistics(TitanStats* stats) { inline Statistics* statistics(TitanStats* stats) {
return (stats) ? stats->statistics() : nullptr; return (stats) ? stats->statistics() : nullptr;
} }
...@@ -191,8 +208,9 @@ inline void SetTickerCount(TitanStats* stats, uint32_t ticker_type, ...@@ -191,8 +208,9 @@ inline void SetTickerCount(TitanStats* stats, uint32_t ticker_type,
} }
} }
// Utility functions for Titan ticker and histogram stats types
inline void ResetStats(TitanStats* stats, uint32_t cf_id, inline void ResetStats(TitanStats* stats, uint32_t cf_id,
TitanInternalStats::StatsType type) { TitanInternalStats::TickerType type) {
if (stats) { if (stats) {
auto p = stats->internal_stats(cf_id); auto p = stats->internal_stats(cf_id);
if (p) { if (p) {
...@@ -202,7 +220,7 @@ inline void ResetStats(TitanStats* stats, uint32_t cf_id, ...@@ -202,7 +220,7 @@ inline void ResetStats(TitanStats* stats, uint32_t cf_id,
} }
inline void AddStats(TitanStats* stats, uint32_t cf_id, inline void AddStats(TitanStats* stats, uint32_t cf_id,
TitanInternalStats::StatsType type, uint64_t value) { TitanInternalStats::TickerType type, uint64_t value) {
if (stats) { if (stats) {
auto p = stats->internal_stats(cf_id); auto p = stats->internal_stats(cf_id);
if (p) { if (p) {
...@@ -212,7 +230,7 @@ inline void AddStats(TitanStats* stats, uint32_t cf_id, ...@@ -212,7 +230,7 @@ inline void AddStats(TitanStats* stats, uint32_t cf_id,
} }
inline void SubStats(TitanStats* stats, uint32_t cf_id, inline void SubStats(TitanStats* stats, uint32_t cf_id,
TitanInternalStats::StatsType type, uint64_t value) { TitanInternalStats::TickerType type, uint64_t value) {
if (stats) { if (stats) {
auto p = stats->internal_stats(cf_id); auto p = stats->internal_stats(cf_id);
if (p) { if (p) {
...@@ -221,6 +239,18 @@ inline void SubStats(TitanStats* stats, uint32_t cf_id, ...@@ -221,6 +239,18 @@ inline void SubStats(TitanStats* stats, uint32_t cf_id,
} }
} }
inline void MeasureTime(TitanStats* stats, uint32_t cf_id,
TitanInternalStats::HistogramType histogram_type,
uint64_t time) {
if (stats) {
auto p = stats->internal_stats(cf_id);
if (p) {
p->MeasureTime(histogram_type, time);
}
}
}
// Utility functions for Titan internal operation stats type
inline uint64_t GetAndResetStats(InternalOpStats* stats, inline uint64_t GetAndResetStats(InternalOpStats* stats,
InternalOpStatsType type) { InternalOpStatsType type) {
if (stats != nullptr) { if (stats != nullptr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment