Open peroket opened 11 months ago
Thank you for reporting this issue. This feature combination: user-defined timestamp and kDataBlockBinaryAndHash
is indeed not compatible. We internally disable this feature combination by making the Comparator:: CanKeysWithDifferentByteContentsBeEqual()
return true.
@jowlyzhang : Do you have any idea when/if this will get prioritized?
This work is not currently planned.
I'm interesting in working on this! As a first step the plan would be something like the following:
The idea is to ensure correct/expected results, although without getting the CPU/throughput improvements from the hash index.
From there, I'd like to experiment with strategies for using/modifying the hash index in a timestamp-aware way to recoup at least some of these benefits in the presence of user-defined timestamps.
@brennan913 thank you for offering to add improvements! Just want to provide a bit more context in order to dive in what specific areas we want to improve.
We are using this API as the source of truth for whether data block hash index is supported: https://github.com/facebook/rocksdb/blob/24045549a61d755418d5e9e6b208b2bfd77093b8/include/rocksdb/comparator.h#L111-L115
Data block's hash index is supported if the comparator defines this function to return false, and specify table_options.data_block_index_type
to be kDataBlockBinaryAndHash
. This logic is here: https://github.com/facebook/rocksdb/blob/24045549a61d755418d5e9e6b208b2bfd77093b8/table/block_based/block_based_table_builder.cc#L467-L470
RocksDB's built in timestamp aware comparator doesn't support data block hash index, so its implementation of CanKeysWithDifferentByteContentsBeEqual
explicitly return true. So for the built in comparator, we don't need to do more things to make sure if timestamp is provided, bypass the hash index even if it's enabled.
If you mean to implement this for other customized comparators, it's better to continue to use the same API.
As for "if no timestamp is provided, check the hash index if it's enabled", no specific things need to be done here. If hash index is used to build a data block, it's encoded into the block and will be used when reading the block. For example, see code snippet here: https://github.com/facebook/rocksdb/blob/24045549a61d755418d5e9e6b208b2bfd77093b8/table/block_based/block.cc#L1083-L1094
If using timestamp and rocksdb::BlockBasedTableOptions::kDataBlockBinaryAndHash, the returned value in Get() is not the latest value.
Expected behavior
Enabling the index should not affect the returned value.
Actual behavior
The returned value is not the most recent one.
Steps to reproduce the behavior
Tested with rocksdb 8.8.1 and catch2.