InternalStats to take cfd on constructor

Summary:
It has one-to-one relationship with CFD. Take a pointer to CFD on
constructor to avoid passing cfd through member functions.

Test Plan: make

Reviewers: sdong, yhchiang, igor

Reviewed By: igor

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D20565
main
Lei Jin 11 years ago
parent 1bd3431f7c
commit 7e8bb71dd0
  1. 2
      db/column_family.cc
  2. 12
      db/db_impl.cc
  3. 31
      db/internal_stats.cc
  4. 8
      db/internal_stats.h

@ -223,7 +223,7 @@ ColumnFamilyData::ColumnFamilyData(const std::string& dbname, uint32_t id,
// if dummy_versions is nullptr, then this is a dummy column family. // if dummy_versions is nullptr, then this is a dummy column family.
if (dummy_versions != nullptr) { if (dummy_versions != nullptr) {
internal_stats_.reset( internal_stats_.reset(
new InternalStats(options_.num_levels, db_options->env)); new InternalStats(options_.num_levels, db_options->env, this));
table_cache_.reset(new TableCache(&options_, storage_options, table_cache)); table_cache_.reset(new TableCache(&options_, storage_options, table_cache));
if (options_.compaction_style == kCompactionStyleUniversal) { if (options_.compaction_style == kCompactionStyleUniversal) {
compaction_picker_.reset( compaction_picker_.reset(

@ -514,17 +514,16 @@ void DBImpl::MaybeDumpStats() {
last_stats_dump_time_microsec_ = now_micros; last_stats_dump_time_microsec_ = now_micros;
DBPropertyType cf_property_type = GetPropertyType("rocksdb.cfstats"); DBPropertyType cf_property_type = GetPropertyType("rocksdb.cfstats");
DBPropertyType db_property_type = GetPropertyType("rocksdb.dbstats");
std::string stats; std::string stats;
{ {
MutexLock l(&mutex_); MutexLock l(&mutex_);
for (auto cfd : *versions_->GetColumnFamilySet()) { for (auto cfd : *versions_->GetColumnFamilySet()) {
cfd->internal_stats()->GetProperty(cf_property_type, "rocksdb.cfstats", cfd->internal_stats()->GetProperty(
&stats, cfd); cf_property_type, "rocksdb.cfstats", &stats);
} }
DBPropertyType db_property_type = GetPropertyType("rocksdb.dbstats");
default_cf_internal_stats_->GetProperty( default_cf_internal_stats_->GetProperty(
db_property_type, "rocksdb.dbstats", &stats, db_property_type, "rocksdb.dbstats", &stats);
default_cf_handle_->cfd());
} }
Log(options_.info_log, "------- DUMPING STATS -------"); Log(options_.info_log, "------- DUMPING STATS -------");
Log(options_.info_log, "%s", stats.c_str()); Log(options_.info_log, "%s", stats.c_str());
@ -4370,8 +4369,7 @@ bool DBImpl::GetProperty(ColumnFamilyHandle* column_family,
auto cfd = cfh->cfd(); auto cfd = cfh->cfd();
DBPropertyType property_type = GetPropertyType(property); DBPropertyType property_type = GetPropertyType(property);
MutexLock l(&mutex_); MutexLock l(&mutex_);
return cfd->internal_stats()->GetProperty(property_type, property, value, return cfd->internal_stats()->GetProperty(property_type, property, value);
cfd);
} }
void DBImpl::GetApproximateSizes(ColumnFamilyHandle* column_family, void DBImpl::GetApproximateSizes(ColumnFamilyHandle* column_family,

@ -125,9 +125,8 @@ DBPropertyType GetPropertyType(const Slice& property) {
} }
bool InternalStats::GetProperty(DBPropertyType property_type, bool InternalStats::GetProperty(DBPropertyType property_type,
const Slice& property, std::string* value, const Slice& property, std::string* value) {
ColumnFamilyData* cfd) { Version* current = cfd_->current();
Version* current = cfd->current();
Slice in = property; Slice in = property;
switch (property_type) { switch (property_type) {
@ -161,16 +160,16 @@ bool InternalStats::GetProperty(DBPropertyType property_type,
return true; return true;
} }
case kStats: { case kStats: {
if (!GetProperty(kCFStats, "rocksdb.cfstats", value, cfd)) { if (!GetProperty(kCFStats, "rocksdb.cfstats", value)) {
return false; return false;
} }
if (!GetProperty(kDBStats, "rocksdb.dbstats", value, cfd)) { if (!GetProperty(kDBStats, "rocksdb.dbstats", value)) {
return false; return false;
} }
return true; return true;
} }
case kCFStats: { case kCFStats: {
DumpCFStats(value, cfd); DumpCFStats(value);
return true; return true;
} }
case kDBStats: { case kDBStats: {
@ -181,11 +180,11 @@ bool InternalStats::GetProperty(DBPropertyType property_type,
*value = current->DebugString(); *value = current->DebugString();
return true; return true;
case kNumImmutableMemTable: case kNumImmutableMemTable:
*value = std::to_string(cfd->imm()->size()); *value = std::to_string(cfd_->imm()->size());
return true; return true;
case kMemtableFlushPending: case kMemtableFlushPending:
// Return number of mem tables that are ready to flush (made immutable) // Return number of mem tables that are ready to flush (made immutable)
*value = std::to_string(cfd->imm()->IsFlushPending() ? 1 : 0); *value = std::to_string(cfd_->imm()->IsFlushPending() ? 1 : 0);
return true; return true;
case kCompactionPending: case kCompactionPending:
// 1 if the system already determines at least one compacdtion is needed. // 1 if the system already determines at least one compacdtion is needed.
@ -198,15 +197,15 @@ bool InternalStats::GetProperty(DBPropertyType property_type,
return true; return true;
case kCurSizeActiveMemTable: case kCurSizeActiveMemTable:
// Current size of the active memtable // Current size of the active memtable
*value = std::to_string(cfd->mem()->ApproximateMemoryUsage()); *value = std::to_string(cfd_->mem()->ApproximateMemoryUsage());
return true; return true;
case kNumEntriesInMutableMemtable: case kNumEntriesInMutableMemtable:
// Current size of the active memtable // Current size of the active memtable
*value = std::to_string(cfd->mem()->GetNumEntries()); *value = std::to_string(cfd_->mem()->GetNumEntries());
return true; return true;
case kNumEntriesInImmutableMemtable: case kNumEntriesInImmutableMemtable:
// Current size of the active memtable // Current size of the active memtable
*value = std::to_string(cfd->imm()->current()->GetTotalNumEntries()); *value = std::to_string(cfd_->imm()->current()->GetTotalNumEntries());
return true; return true;
default: default:
return false; return false;
@ -283,12 +282,12 @@ void InternalStats::DumpDBStats(std::string* value) {
db_stats_snapshot_.write_with_wal = write_with_wal; db_stats_snapshot_.write_with_wal = write_with_wal;
} }
void InternalStats::DumpCFStats(std::string* value, ColumnFamilyData* cfd) { void InternalStats::DumpCFStats(std::string* value) {
Version* current = cfd->current(); Version* current = cfd_->current();
int num_levels_to_check = int num_levels_to_check =
(cfd->options()->compaction_style != kCompactionStyleUniversal && (cfd_->options()->compaction_style != kCompactionStyleUniversal &&
cfd->options()->compaction_style != kCompactionStyleFIFO) cfd_->options()->compaction_style != kCompactionStyleFIFO)
? current->NumberLevels() - 1 ? current->NumberLevels() - 1
: 1; : 1;
// Compaction scores are sorted base on its value. Restore them to the // Compaction scores are sorted base on its value. Restore them to the
@ -310,7 +309,7 @@ void InternalStats::DumpCFStats(std::string* value, ColumnFamilyData* cfd) {
char buf[1000]; char buf[1000];
// Per-ColumnFamily stats // Per-ColumnFamily stats
PrintLevelStatsHeader(buf, sizeof(buf), cfd->GetName()); PrintLevelStatsHeader(buf, sizeof(buf), cfd_->GetName());
value->append(buf); value->append(buf);
CompactionStats stats_sum(0); CompactionStats stats_sum(0);

@ -64,7 +64,7 @@ class InternalStats {
INTERNAL_DB_STATS_ENUM_MAX, INTERNAL_DB_STATS_ENUM_MAX,
}; };
InternalStats(int num_levels, Env* env) InternalStats(int num_levels, Env* env, ColumnFamilyData* cfd)
: db_stats_(INTERNAL_DB_STATS_ENUM_MAX), : db_stats_(INTERNAL_DB_STATS_ENUM_MAX),
cf_stats_value_(INTERNAL_CF_STATS_ENUM_MAX), cf_stats_value_(INTERNAL_CF_STATS_ENUM_MAX),
cf_stats_count_(INTERNAL_CF_STATS_ENUM_MAX), cf_stats_count_(INTERNAL_CF_STATS_ENUM_MAX),
@ -76,6 +76,7 @@ class InternalStats {
bg_error_count_(0), bg_error_count_(0),
number_levels_(num_levels), number_levels_(num_levels),
env_(env), env_(env),
cfd_(cfd),
started_at_(env->NowMicros()) { started_at_(env->NowMicros()) {
for (int i = 0; i< INTERNAL_DB_STATS_ENUM_MAX; ++i) { for (int i = 0; i< INTERNAL_DB_STATS_ENUM_MAX; ++i) {
db_stats_[i] = 0; db_stats_[i] = 0;
@ -189,11 +190,11 @@ class InternalStats {
uint64_t BumpAndGetBackgroundErrorCount() { return ++bg_error_count_; } uint64_t BumpAndGetBackgroundErrorCount() { return ++bg_error_count_; }
bool GetProperty(DBPropertyType property_type, const Slice& property, bool GetProperty(DBPropertyType property_type, const Slice& property,
std::string* value, ColumnFamilyData* cfd); std::string* value);
private: private:
void DumpDBStats(std::string* value); void DumpDBStats(std::string* value);
void DumpCFStats(std::string* value, ColumnFamilyData* cfd); void DumpCFStats(std::string* value);
// Per-DB stats // Per-DB stats
std::vector<uint64_t> db_stats_; std::vector<uint64_t> db_stats_;
@ -254,6 +255,7 @@ class InternalStats {
const int number_levels_; const int number_levels_;
Env* env_; Env* env_;
ColumnFamilyData* cfd_;
const uint64_t started_at_; const uint64_t started_at_;
}; };

Loading…
Cancel
Save