Skip to content

Commit

Permalink
[RocksDB] Add db property "rocksdb.cur-size-active-mem-table"
Browse files Browse the repository at this point in the history
Summary: as title

Test Plan: db_test

Reviewers: sdong

Reviewed By: sdong

CC: leveldb

Differential Revision: https://reviews.facebook.net/D17217
  • Loading branch information
haoboxu committed Mar 27, 2014
1 parent b14c1f9 commit a92194e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
3 changes: 1 addition & 2 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class DBImpl : public DB {

private:
friend class DB;
friend class InternalStats;
friend class TailingIterator;
friend struct SuperVersion;
struct CompactionState;
Expand Down
7 changes: 7 additions & 0 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}
Expand Down
14 changes: 10 additions & 4 deletions db/internal_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions db/internal_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace rocksdb {

class MemTableList;
class DBImpl;

enum DBPropertyType {
kNumFilesAtLevel, // Number of files at a specific level
Expand All @@ -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,
};

Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit a92194e

Please sign in to comment.