Essentially, you can use db->GetProperty("rocksdb.estimate-num-keys", &num) to get an estimated number of keys stored in rockdb.
Another option is to use the sst_dump tool with the --show_properties argument to get the number of records, although the result will be based on each file. For example, the following command will show the properties of each SST file in the specified rockdb directory:
sst_dump --file=/tmp/rocksdbtest-691931916/dbbench --show_properties --command=none
And here is an example output:
Process /tmp/rocksdbtest-691931916/dbbench/000005.sst Sst file format: block-based Table Properties: ------------------------------
Combine with some shell commands, you can get the total number of entries:
sst_dump --file=/tmp/rocksdbtest-691931916/dbbench --show_properties --command=none | grep entries | cut -c 14- | awk '{x+=$0}END{print "total number of entries: " x}'
And this will generate the following output:
total number of entries: 111507
source share