[RocksDB] Add db property "rocksdb.cur-size-active-mem-table"

Summary: as title

Test Plan: db_test

Reviewers: sdong

Reviewed By: sdong

CC: leveldb

Differential Revision: https://reviews.facebook.net/D17217
main
Haobo Xu 11 years ago
parent b14c1f995b
commit a92194e5b2
  1. 3
      db/db_impl.cc
  2. 1
      db/db_impl.h
  3. 7
      db/db_test.cc
  4. 14
      db/internal_stats.cc
  5. 5
      db/internal_stats.h

@ -4089,8 +4089,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
value->clear();
DBPropertyType property_type = GetPropertyType(property);
MutexLock l(&mutex_);
return internal_stats_.GetProperty(property_type, property, value,
versions_.get(), imm_);
return internal_stats_.GetProperty(property_type, property, value, this);
}
void DBImpl::GetApproximateSizes(

@ -297,6 +297,7 @@ class DBImpl : public DB {
private:
friend class DB;
friend class InternalStats;
friend class TailingIterator;
friend struct SuperVersion;
struct CompactionState;

@ -2036,6 +2036,8 @@ TEST(DBTest, NumImmutableMemTable) {
ASSERT_EQ(1, (int) perf_context.get_from_memtable_count);
ASSERT_OK(dbfull()->Put(writeOpt, "k3", big_value));
ASSERT_TRUE(dbfull()->GetProperty("rocksdb.cur-size-active-mem-table",
&num));
ASSERT_TRUE(dbfull()->GetProperty("rocksdb.num-immutable-mem-table", &num));
ASSERT_EQ(num, "2");
perf_context.Reset();
@ -2051,6 +2053,11 @@ TEST(DBTest, NumImmutableMemTable) {
dbfull()->Flush(FlushOptions());
ASSERT_TRUE(dbfull()->GetProperty("rocksdb.num-immutable-mem-table", &num));
ASSERT_EQ(num, "0");
ASSERT_TRUE(dbfull()->GetProperty("rocksdb.cur-size-active-mem-table",
&num));
// "208" is the size of the metadata of an empty skiplist, this would
// break if we change the default skiplist implementation
ASSERT_EQ(num, "208");
SetPerfLevel(kDisable);
} while (ChangeCompactOptions());
}

@ -7,6 +7,7 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "db/internal_stats.h"
#include "db/db_impl.h"
#include "db/memtable_list.h"
#include <vector>
@ -35,15 +36,18 @@ DBPropertyType GetPropertyType(const Slice& property) {
return kCompactionPending;
} else if (in == "background-errors") {
return kBackgroundErrors;
} else if (in == "cur-size-active-mem-table") {
return kCurSizeActiveMemTable;
}
return kUnknown;
}
bool InternalStats::GetProperty(DBPropertyType property_type,
const Slice& property, std::string* value,
VersionSet* version_set,
const MemTableList& imm) {
DBImpl* db) {
VersionSet* version_set = db->versions_.get();
Version* current = version_set->current();
const MemTableList& imm = db->imm_;
Slice in = property;
switch (property_type) {
@ -341,12 +345,14 @@ bool InternalStats::GetProperty(DBPropertyType property_type,
// 0 otherwise,
*value = std::to_string(current->NeedsCompaction() ? 1 : 0);
return true;
/////////////
case kBackgroundErrors:
// Accumulated number of errors in background flushes or compactions.
*value = std::to_string(GetBackgroundErrorCount());
return true;
/////////
case kCurSizeActiveMemTable:
// Current size of the active memtable
*value = std::to_string(db->mem_->ApproximateMemoryUsage());
return true;
default:
return false;
}

@ -19,6 +19,7 @@
namespace rocksdb {
class MemTableList;
class DBImpl;
enum DBPropertyType {
kNumFilesAtLevel, // Number of files at a specific level
@ -31,6 +32,7 @@ enum DBPropertyType {
// 0.
kCompactionPending, // Return 1 if a compaction is pending. Otherwise 0.
kBackgroundErrors, // Return accumulated background errors encountered.
kCurSizeActiveMemTable, // Return current size of the active memtable
kUnknown,
};
@ -124,8 +126,7 @@ class InternalStats {
uint64_t BumpAndGetBackgroundErrorCount() { return ++bg_error_count_; }
bool GetProperty(DBPropertyType property_type, const Slice& property,
std::string* value, VersionSet* version_set,
const MemTableList& imm);
std::string* value, DBImpl* db);
private:
std::vector<CompactionStats> compaction_stats_;

Loading…
Cancel
Save