Add bloom filter to predefined table stats

Summary: As title.

Test Plan: Updated the unit tests to make sure new statistic is correctly written/read.

Reviewers: dhruba, haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D13497
main
Kai Liu 11 years ago
parent 6731997f64
commit aac44226a0
  1. 4
      include/rocksdb/table_stats.h
  2. 20
      table/table.cc
  3. 1
      table/table.h
  4. 6
      table/table_builder.cc
  5. 14
      table/table_test.cc

@ -35,6 +35,10 @@ struct TableStats {
// the number of entries in this table // the number of entries in this table
uint64_t num_entries = 0; uint64_t num_entries = 0;
// The name of the filter policy used in this table.
// If no filter policy is used, `filter_policy_name` will be an empty string.
std::string filter_policy_name;
// user collected stats // user collected stats
UserCollectedStats user_collected_stats; UserCollectedStats user_collected_stats;
}; };

@ -269,7 +269,8 @@ Status Table::ReadStats(const Slice& handle_value, Rep* rep) {
); );
auto& table_stats = rep->table_stats; auto& table_stats = rep->table_stats;
std::unordered_map<std::string, uint64_t*> predefined_name_stat_map = { // All pre-defined stats of type uint64_t
std::unordered_map<std::string, uint64_t*> predefined_uint64_stats = {
{ TableStatsNames::kDataSize, &table_stats.data_size }, { TableStatsNames::kDataSize, &table_stats.data_size },
{ TableStatsNames::kIndexSize, &table_stats.index_size }, { TableStatsNames::kIndexSize, &table_stats.index_size },
{ TableStatsNames::kRawKeySize, &table_stats.raw_key_size }, { TableStatsNames::kRawKeySize, &table_stats.raw_key_size },
@ -294,14 +295,9 @@ Status Table::ReadStats(const Slice& handle_value, Rep* rep) {
last_key = key; last_key = key;
auto raw_val = iter->value(); auto raw_val = iter->value();
auto pos = predefined_name_stat_map.find(key); auto pos = predefined_uint64_stats.find(key);
if (pos == predefined_name_stat_map.end()) { if (pos != predefined_uint64_stats.end()) {
// handle user-collected
table_stats.user_collected_stats.insert(
std::make_pair(iter->key().ToString(), raw_val.ToString())
);
} else {
// handle predefined rocksdb stats // handle predefined rocksdb stats
uint64_t val; uint64_t val;
if (!GetVarint64(&raw_val, &val)) { if (!GetVarint64(&raw_val, &val)) {
@ -313,6 +309,13 @@ Status Table::ReadStats(const Slice& handle_value, Rep* rep) {
continue; continue;
} }
*(pos->second) = val; *(pos->second) = val;
} else if (key == TableStatsNames::kFilterPolicy) {
table_stats.filter_policy_name = raw_val.ToString();
} else {
// handle user-collected
table_stats.user_collected_stats.insert(
std::make_pair(iter->key().ToString(), raw_val.ToString())
);
} }
} }
@ -608,5 +611,6 @@ const std::string TableStatsNames::kRawKeySize = "rocksdb.raw.key.size";
const std::string TableStatsNames::kRawValueSize = "rocksdb.raw.value.size"; const std::string TableStatsNames::kRawValueSize = "rocksdb.raw.value.size";
const std::string TableStatsNames::kNumDataBlocks = "rocksdb.num.data.blocks"; const std::string TableStatsNames::kNumDataBlocks = "rocksdb.num.data.blocks";
const std::string TableStatsNames::kNumEntries = "rocksdb.num.entries"; const std::string TableStatsNames::kNumEntries = "rocksdb.num.entries";
const std::string TableStatsNames::kFilterPolicy = "rocksdb.filter.policy";
} // namespace rocksdb } // namespace rocksdb

@ -120,6 +120,7 @@ struct TableStatsNames {
static const std::string kRawValueSize; static const std::string kRawValueSize;
static const std::string kNumDataBlocks; static const std::string kNumDataBlocks;
static const std::string kNumEntries; static const std::string kNumEntries;
static const std::string kFilterPolicy;
}; };
} // namespace rocksdb } // namespace rocksdb

@ -368,6 +368,12 @@ Status TableBuilder::Finish() {
); );
AddStats(stats, TableStatsNames::kNumEntries, r->num_entries); AddStats(stats, TableStatsNames::kNumEntries, r->num_entries);
AddStats(stats, TableStatsNames::kNumDataBlocks, r->num_data_blocks); AddStats(stats, TableStatsNames::kNumDataBlocks, r->num_data_blocks);
if (r->filter_block != nullptr) {
stats.insert(std::make_pair(
TableStatsNames::kFilterPolicy,
r->options.filter_policy->Name()
));
}
for (const auto& stat : stats) { for (const auto& stat : stats) {
stats_block.Add(stat.first, stat.second); stats_block.Add(stat.first, stat.second);

@ -886,6 +886,7 @@ TEST(TableTest, BasicTableStats) {
ASSERT_EQ(raw_key_size, stats.raw_key_size); ASSERT_EQ(raw_key_size, stats.raw_key_size);
ASSERT_EQ(raw_value_size, stats.raw_value_size); ASSERT_EQ(raw_value_size, stats.raw_value_size);
ASSERT_EQ(1ul, stats.num_data_blocks); ASSERT_EQ(1ul, stats.num_data_blocks);
ASSERT_EQ("", stats.filter_policy_name); // no filter policy is used
// Verify data size. // Verify data size.
BlockBuilder block_builder(&options); BlockBuilder block_builder(&options);
@ -899,6 +900,19 @@ TEST(TableTest, BasicTableStats) {
); );
} }
TEST(TableTest, FilterPolicyNameStats) {
TableConstructor c(BytewiseComparator());
c.Add("a1", "val1");
std::vector<std::string> keys;
KVMap kvmap;
Options options;
options.filter_policy = NewBloomFilterPolicy(10);
c.Finish(options, &keys, &kvmap);
auto& stats = c.table()->GetTableStats();
ASSERT_EQ("rocksdb.BuiltinBloomFilter", stats.filter_policy_name);
}
static std::string RandomString(Random* rnd, int len) { static std::string RandomString(Random* rnd, int len) {
std::string r; std::string r;
test::RandomString(rnd, len, &r); test::RandomString(rnd, len, &r);

Loading…
Cancel
Save