9

是否可以有效地获取存储在 RocksDB 键值存储中的键值对的数量?

我浏览了wiki,到目前为止还没有看到任何讨论这个话题的东西。这样的操作甚至可能吗?

4

2 回答 2

12

在代码方面,您可以使用db->GetProperty("rocksdb.estimate-num-keys", &num)来获取存储在 RocksDB 中的估计键数。

另一种选择是使用sst_dump带有--show_properties参数的工具来获取条目数,尽管结果将基于每个文件。例如,以下命令将显示指定rocksdb目录下每个SST文件的属性:

sst_dump --file=/tmp/rocksdbtest-691931916/dbbench --show_properties --command=none

这是示例输出:

Process /tmp/rocksdbtest-691931916/dbbench/000005.sst
Sst file format: block-based
Table Properties:
------------------------------
  # data blocks: 845
  # entries: 27857
  raw key size: 668568
  raw average key size: 24.000000
  raw value size: 2785700
  raw average value size: 100.000000
  data block size: 3381885
  index block size: 28473
  filter block size: 0
  (estimated) table size: 3410358
  filter policy name: N/A
  # deleted keys: 0
Process /tmp/rocksdbtest-691931916/dbbench/000008.sst
Sst file format: block-based
Table Properties:
------------------------------
  # data blocks: 845
  # entries: 27880
  raw key size: 669120
...

结合一些shell命令,您将能够获得条目总数:

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}'

这将生成以下输出:

total number of entries: 111507
于 2014-09-10T22:08:24.113 回答
2

没有办法准确地得到计数。但是在最近发布的rocksdb 3.4中,它公开了一种获取key的估计计数的方法,你可以试试。

https://github.com/facebook/rocksdb/releases

于 2014-08-31T11:06:58.237 回答