The questions about prefix seek method
Version: RocksDB, 5.17.2
Behavior
We use prefix seek method to seek the key, we found that the result was smaller than the key.
for example: iter->seek(234) the return value is 223
Questions
I noticed that there are 4 rules to follow when we implemented prefix_extractor ourselves. // 1) key.starts_with(prefix(key)) // 2) Compare(prefix(key), key) <= 0. // 3) If Compare(k1, k2) <= 0, then Compare(prefix(k1), prefix(k2)) <= 0 // 4) prefix(prefix(key)) == prefix(key)
Our prefix_extractor transform implementation is truncate the last 16 digits of the key. And it does not satisfy rule4.
Is this the cause of the above problem? Will we lose data?
Thanks a lot @siying @ajkr @yiwu-arbug
Perhaps the core of the question should be why the fourth condition is needed? When will the prefix calculation be performed twice (or more than twice) on a key?
There was some legacy code that would do prefix(prefix(key)) during filter block construction to check if the prefix being added to the filter was same as the last entry added. It would do prefix(last_entry), and last_entry could either be a whole key or prefix.
Its no longer done that way. During filter construction, we record the last whole key added as well as last prefix added in separate variables, so we don't have to do prefix(prefix(key)).
@anand1976 Thanks for your reply and explain, as you said i check the code,the last prefix was indeed recorded by the prev_prefix_start_ variable.
So the above problem is not caused by the prefix seek.
I still can not understand why seek(key) will return a value that smaller than (key). Would you give me some hints?