Whenever I put value in rocksdb for the same key, the value get updated and count also gets increased

3.2k Views Asked by At

Whenever I put value in rocksdb for the same key. The value get updated. But the count by the following method db.getLongProperty(columnFamily, "rocksdb.estimate-num-keys") gets incremented. Why am I getting this weird behavior?

1

There are 1 best solutions below

0
On

That is the expected behaviour in rocksdb. Note that the property is estimate-num-keys, meaning it will only give you an estimate( not exact ) of the number of keys present in the db. You might have to run a full compaction on the column family to get the accurate number of keys present.

Quoting from the WIKI,

Q: Why GetIntProperty can only returns an estimated number of keys in a RocksDB database?

A: Obtaining an accurate number of keys in any LSM databases like RocksDB is a challenging problem as they have duplicate keys and deletion entries (i.e., tombstones) that will require a full compaction in order to get an accurate number of keys. In addition, if the RocksDB database contains merge operators, it will also make the estimated number of keys less accurate.

You can also check the rocksdb option - inplace_update_support which will update the key if it exists in memtable itself instead of writing it again.