Skip to content

Conversation

@cb1kenobi
Copy link
Contributor

@cb1kenobi cb1kenobi commented Jun 2, 2025

Support for key range related database methods:

  • db.getRange()
  • db.getKeys()
  • db.getKeysCount()

There's a new NativeIterator internal class that exposes the RocksDB iterator instance along with a plethora of RocksDB specific iterator config settings.

Note: version support has not be implemented, so getValuesCount() is technically incomplete.

Base automatically changed from transaction-refactor to northstar June 3, 2025 18:08
@cb1kenobi cb1kenobi marked this pull request as ready for review June 10, 2025 16:14
@cb1kenobi cb1kenobi requested a review from a team June 10, 2025 16:36
Copy link
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

The code looks great, but I am a little confused as to the state of iterators. Currently, it looks like this is using iterator.ts, but I thought this was supposed to be using harperdb/extended-iterable. And the description says it is blocked by the PR in the extended-iterable repo, is that true? Is the PR necessary for this to work?

@cb1kenobi
Copy link
Contributor Author

The code looks great, but I am a little confused as to the state of iterators. Currently, it looks like this is using iterator.ts, but I thought this was supposed to be using harperdb/extended-iterable. And the description says it is blocked by the PR in the extended-iterable repo, is that true? Is the PR necessary for this to work?

The iterable work started in iterator.ts, but I'm around 99% donee moving it to extended-iterable. I read that extended-iterable not as high priority as dupSort. I'll find time to get the iterable work over the finish line. We should not merge this PR until the extended-iterable is ready.

I am now focused on the dupSort functionality which is high priority. I'm working on in a branch from this key ranges branch. I'm testing getValues() and finding the key range isn't working as I expected. I'm actively working on it and will ensure this PR gets updated.

@kriszyp
Copy link
Member

kriszyp commented Jun 18, 2025 via email

@kriszyp
Copy link
Member

kriszyp commented Jun 24, 2025

There is considerable complexity involved in trying to replace lmdb-js with rocksdb-js and trying to replace the iterable module at the same time. When I tried using https://github.com/HarperDB/extended-iterable/pull/1/files with lmdb-js it immediately failed due to premature creation of the iterator on construction. I believe there is a considerable amount of work required of us to fully test and evaluate all the new extended-iterable code in the three places it will be used: lmdb-js (as used in Harper), Harper's query engine, and rocksdb-js (as used in Harper), and at least I don't have a lot of extra time for that right now.

I think it would greatly beneficial to us if we could get this PR working with extended-iterable v1. And then once we have rocksdb working Harper (minimizing other changes involved), we could then apply extended-iterable v2 upgrades in more isolated and planned manner, rather than trying to do it all at once.

@cb1kenobi cb1kenobi requested a review from a team June 26, 2025 14:22
@cb1kenobi
Copy link
Contributor Author

I've removed the initial iterator implementation and replaced it with the complete extended-iterable v2.

Copy link
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

The original request for this functionality was to use the lmdb-js's RangeIterable code. #29 explicitly pulled the RangeIterable code into a shared package for use for range iteration, and defined that we use v1 (^1.0.0).
After reviewing HarperFast/extended-iterable#1, I do not feel that v2 is ready for use at this time (although certainly hope to use in the future), and it is not proposed or part of the plan for ranges. Please adjust this PR to use v1 of the extended-iterable. This PR should not be blocked by HarperFast/extended-iterable#1.

napi_value value;

rocksdb::Slice keySlice = itHandle->iterator->key();
NAPI_STATUS_THROWS(::napi_create_buffer_copy(
Copy link
Member

Choose a reason for hiding this comment

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

These buffer creation, object creation, and property setting calls are likely pretty expensive, and the iterator.next function is an extremely hot code path. We don't necessarily need to address this in this PR, and we might want to benchmark/profile to better understand the performance of this, but likely we will have follow-up ticket(s) for addressing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree 100%. I want to create a benchmark suite asap and so we have a baseline for optimizations. In this instance, I could see us using a shared buffer for keys.

Copy link
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

Thank you for your flexibility with this. This is a major milestone in our rocksdb effort. Incredible work.

@cb1kenobi cb1kenobi requested review from a team and kriszyp July 9, 2025 00:00
@cb1kenobi cb1kenobi merged commit e0f97e1 into northstar Jul 9, 2025
12 checks passed
@cb1kenobi cb1kenobi deleted the key-ranges branch July 9, 2025 00:04
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