diff --git a/src/server/pegasus_server_impl.cpp b/src/server/pegasus_server_impl.cpp index 39b96b6d0e..033462b063 100644 --- a/src/server/pegasus_server_impl.cpp +++ b/src/server/pegasus_server_impl.cpp @@ -338,6 +338,13 @@ pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r) snprintf(name, 255, "rdb.memtable.memory_usage@%s", str_gpid.c_str()); _pfc_rdb_memtable_mem_usage.init_app_counter( "app.pegasus", name, COUNTER_TYPE_NUMBER, "statistic the memory usage of rocksdb memtable"); + + snprintf(name, 255, "rdb.estimate_num_keys@%s", str_gpid.c_str()); + _pfc_rdb_estimate_num_keys.init_app_counter( + "app.pegasus", + name, + COUNTER_TYPE_NUMBER, + "statistics the estimated number of keys inside the rocksdb"); } void pegasus_server_impl::parse_checkpoints() @@ -2242,6 +2249,14 @@ void pegasus_server_impl::update_replica_rocksdb_statistics() _pfc_rdb_memtable_mem_usage->set(val); dinfo_replica("_pfc_rdb_memtable_mem_usage: {} bytes", val); } + + // for the same n kv pairs, kEstimateNumKeys will be counted n times, you need compaction to + // remove duplicate + if (_db->GetProperty(rocksdb::DB::Properties::kEstimateNumKeys, &str_val) && + dsn::buf2uint64(str_val, val)) { + _pfc_rdb_estimate_num_keys->set(val); + dinfo_replica("_pfc_rdb_estimate_num_keys: {}", val); + } } void pegasus_server_impl::update_server_rocksdb_statistics() diff --git a/src/server/pegasus_server_impl.h b/src/server/pegasus_server_impl.h index 49e8c7dd3e..9498695ee9 100644 --- a/src/server/pegasus_server_impl.h +++ b/src/server/pegasus_server_impl.h @@ -364,6 +364,7 @@ class pegasus_server_impl : public ::dsn::apps::rrdb_service ::dsn::perf_counter_wrapper _pfc_rdb_block_cache_total_count; ::dsn::perf_counter_wrapper _pfc_rdb_index_and_filter_blocks_mem_usage; ::dsn::perf_counter_wrapper _pfc_rdb_memtable_mem_usage; + ::dsn::perf_counter_wrapper _pfc_rdb_estimate_num_keys; }; } // namespace server