Skip to content
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

DBIterator must be seeked before used #245

Open
Kerollmops opened this issue Dec 3, 2018 · 2 comments
Open

DBIterator must be seeked before used #245

Kerollmops opened this issue Dec 3, 2018 · 2 comments
Assignees

Comments

@Kerollmops
Copy link

Kerollmops commented Dec 3, 2018

I just wanted to inform users of the library that if they can't see any entry using a DBIterator this is probably because they forgot to iter.seek(SeekKey::Start) for example.

It takes me a long time to understand why, I read many things on RocksDB before I decided to look into some iterator tests of this rust wrapper.

https://github.com/pingcap/rust-rocksdb/blob/05aaf93fdceff092768b1e9d50bc13c519d70d76/src/rocksdb.rs#L2378-L2380

@DorianZheng
Copy link

@Kerollmops Mostly because the DBIterator won't position at any key before user calls one of Seek, SeekForPrev, SeekToFirst, or SeekToLast manually. Thank you for informing this, do you think we can close it now?

@Kerollmops
Copy link
Author

Kerollmops commented Dec 5, 2018

I think we can not close it until someone (including me) has made a PR that clarify this behavior and/or change it. Because currently the DBIterator does not follow the RAII rules in the sence that it is not "initialised" just after the creation.

It could be interresting to create something like a DBIteratorBuilder that does not implement the Iterator trait itself but allow the user to build one that follows its requirements.

let iter = db.iter().seek_to_first();

Or something like:

let mut forward_iter = db.iter();

let mut custom_iter = db.iter_builder().seek_for_prev(...);

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

No branches or pull requests

2 participants