8000 Add variable size prefix for key generator class + improve documentation by KareemOtoum · Pull Request #13709 · facebook/rocksdb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add variable size prefix for key generator class + improve documentation #13709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

KareemOtoum
Copy link
@KareemOtoum KareemOtoum commented Jun 18, 2025

This pr adds an unfinished feature in the KeyGenerator class at microbench/db_basic_bench.cc, removing the hard-coded limit for the prefix size of the key generator and improves the documentation of the class.

if (prefix_num > 0) {
      prefix_size_ = 4;  // TODO: support different prefix_size
    }

Previously, the key generator would accept an optional prefix and force a size of 4 bytes if one was provided. The changes in this pr make it so that the constructor accepts a size_t prefix_size = 4 as a parameter to represent the desired bytes for the keys prefix. An assert ensures that the size can represent the given size_t prefix_num.

To support this new feature's addition, the Encode function was also changed to accept a size parameter for encoding a variable size key/prefix while preserving endianness (it is limited to 4 bytes but will be addressed in future pr's where I plan to address the max_keys_ limit aswell).

This change improves flexibility for key generation in benchmarks and tests.

As a next step, I plan to explore increasing the maximum number of keys (max_keys_) that can be generated, which is currently limited by an assert. Feedback on this approach or suggestions for future improvements are welcome!

@KareemOtoum KareemOtoum changed the title Add variable size prefix for microbench/db_basic_bench.cc KeyGenerator class + improve documentation Add variable size prefix for key generator class + improve documentation Jun 21, 2025
bool is_sequential_ = false;
uint32_t next_sequential_key_ = 0;
char buff_[256] = {0};
const int MULTIPLIER = 3;

void static Encode(char* buf, uint32_t value) {
// helper function to encode variable size prefix or key numbers
void static Encode(char* buf, uint32_t value, uint32_t size) {
Copy link
Author
@KareemOtoum KareemOtoum Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that as of now, the encode function can only encode up to 4 bytes for the prefix/key, I am planning on changing this with my next pr where I will look at extending the max number of keys that can be generated.

@KareemOtoum
Copy link
Author

@yiwu-arbug would you be able to look at this pr when you have time? cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0