Skip to content

Conversation

@glyh
Copy link
Member

@glyh glyh commented Oct 16, 2025

To run this test

  • Run install-rocksdb.sh (preferably in a docker because it installs to system library) to ensure rocksdb dyn lib are installed
  • Run test.py inside a venv where everything in requirements.txt is installed

@glyh glyh requested a review from a team as a code owner October 16, 2025 08:42
count = 0
# --- Iterate over all keys ---
rocksdb.rocksdb_iter_seek_to_first(iter_)
while count < 10 and rocksdb.rocksdb_iter_valid(iter_):
Copy link
Member

Choose a reason for hiding this comment

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

why 10?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just a random number, I can add it to params.

print(f"Found KV-pair: {key_buf[:].hex()} -> {val_buf[:].hex()}")

rocksdb.rocksdb_iter_next(iter_)
count += 1
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Ugly count += 1. looks like count is not used further in the script. we can replace while with:

for _ in range(10):
    if not rocksdb.rocksdb_iter_valid(iter_):
        break

rocksdb.rocksdb_iter_next(iter_)
count += 1

# --- Cleanup ---
Copy link
Member

Choose a reason for hiding this comment

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

NIT: This looks like a perfect use case for contextmanager:

  from contextlib import contextmanager

@contextmanager
def open_db(path, options):
    db = rocksdb.rocksdb_open(options, path.encode())
    try:
        yield db
    finally:
        rocksdb.rocksdb_close(db)

@contextmanager
def read_iter(db):
    ropts = rocksdb.rocksdb_readoptions_create()
    iter_ = rocksdb.rocksdb_create_iterator(db, ropts)
    try:
        yield iter_
    finally:
        rocksdb.rocksdb_iter_destroy(iter_)
        rocksdb.rocksdb_readoptions_destroy(ropts)

Copy link
Member

@dkijania dkijania left a comment

Choose a reason for hiding this comment

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

Please consider moving everything from buildkite to scripts folder. Usually we put to buildkite folder stuff which is dependent on buildkite. Looks like it is not a case here

@glyh glyh requested a review from a team as a code owner October 17, 2025 04:39
rocksdb.rocksdb_close(db)

@contextmanager
def read_iter(db):
Copy link
Member Author

Choose a reason for hiding this comment

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

This should better be a generator, I think. Should leave as a follow-up.

BTW, the reason I'm hand-rolling a binding is because other existing libraries is not using dynamic linking.

@glyh
Copy link
Member Author

glyh commented Oct 17, 2025

Superceded by #17957

@glyh glyh closed this Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants