rust-rocksdb
rust-rocksdb copied to clipboard
DBIterator must be seeked before used
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 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?
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(...);