rust-rocksdb icon indicating copy to clipboard operation
rust-rocksdb copied to clipboard

DBIterator must be seeked before used

Open Kerollmops opened this issue 6 years ago • 2 comments

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

Kerollmops avatar Dec 03 '18 21:12 Kerollmops

@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?

DorianZheng avatar Dec 05 '18 09:12 DorianZheng

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(...);

Kerollmops avatar Dec 05 '18 12:12 Kerollmops