Skip to content

Commit 3ab1a07

Browse files
forevernevererwutao1
authored andcommitted
feat(collector): add statistics for estimate key number of partition (#435)
1 parent 00ff3da commit 3ab1a07

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/server/pegasus_server_impl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r)
338338
snprintf(name, 255, "rdb.memtable.memory_usage@%s", str_gpid.c_str());
339339
_pfc_rdb_memtable_mem_usage.init_app_counter(
340340
"app.pegasus", name, COUNTER_TYPE_NUMBER, "statistic the memory usage of rocksdb memtable");
341+
342+
snprintf(name, 255, "rdb.estimate_num_keys@%s", str_gpid.c_str());
343+
_pfc_rdb_estimate_num_keys.init_app_counter(
344+
"app.pegasus",
345+
name,
346+
COUNTER_TYPE_NUMBER,
347+
"statistics the estimated number of keys inside the rocksdb");
341348
}
342349

343350
void pegasus_server_impl::parse_checkpoints()
@@ -2242,6 +2249,14 @@ void pegasus_server_impl::update_replica_rocksdb_statistics()
22422249
_pfc_rdb_memtable_mem_usage->set(val);
22432250
dinfo_replica("_pfc_rdb_memtable_mem_usage: {} bytes", val);
22442251
}
2252+
2253+
// for the same n kv pairs, kEstimateNumKeys will be counted n times, you need compaction to
2254+
// remove duplicate
2255+
if (_db->GetProperty(rocksdb::DB::Properties::kEstimateNumKeys, &str_val) &&
2256+
dsn::buf2uint64(str_val, val)) {
2257+
_pfc_rdb_estimate_num_keys->set(val);
2258+
dinfo_replica("_pfc_rdb_estimate_num_keys: {}", val);
2259+
}
22452260
}
22462261

22472262
void pegasus_server_impl::update_server_rocksdb_statistics()

src/server/pegasus_server_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class pegasus_server_impl : public ::dsn::apps::rrdb_service
364364
::dsn::perf_counter_wrapper _pfc_rdb_block_cache_total_count;
365365
::dsn::perf_counter_wrapper _pfc_rdb_index_and_filter_blocks_mem_usage;
366366
::dsn::perf_counter_wrapper _pfc_rdb_memtable_mem_usage;
367+
::dsn::perf_counter_wrapper _pfc_rdb_estimate_num_keys;
367368
};
368369

369370
} // namespace server

0 commit comments

Comments
 (0)