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

Iterators don't stop iterating when specified "to" key is reached. #43

Open
palkeo opened this issue Dec 22, 2020 · 3 comments
Open

Iterators don't stop iterating when specified "to" key is reached. #43

palkeo opened this issue Dec 22, 2020 · 3 comments

Comments

@palkeo
Copy link

palkeo commented Dec 22, 2020

If I instantiate a leveldb iterator like so:

            leveldb
                .iter(ReadOptions::new())
                .from(start_key)
                .to(stop_key)

I would expect the iteration to start at (or after) start_key, and stop at (or before) stop_key.
Here iteration do start after start_key, but never stops before the end of the DB is reached.

@skade skade added the bug label Jan 6, 2021
@skade
Copy link
Owner

skade commented Jan 6, 2021

Can you provide a reduced test case for this?

@palkeo
Copy link
Author

palkeo commented Jan 7, 2021

Here you go, this could be added to tests/iterator.rs, and is a failing test I would expect to pass:

#[test]
fn test_key_iterator_iterate_from_to() {
  let tmp = tmpdir("key_iter");
  let database = &mut open_database(tmp.path(), true);
  db_put_simple(database, 1, &[1]);
  db_put_simple(database, 2, &[2]);
  db_put_simple(database, 3, &[3]);
  db_put_simple(database, 4, &[4]);
  db_put_simple(database, 5, &[5]);

  let iterable: &mut Iterable<i32> = database;

  let read_opts = ReadOptions::new();
  let mut iter = iterable.keys_iter(read_opts).from(&2).to(&4);
  let vec: Vec<i32> = iter.collect();
  assert_eq!(vec, vec![2, 3, 4]);
}

@jszwedko
Copy link

We just ran into this today.

It seems like there is no check against the end key here https://docs.rs/leveldb/0.8.6/src/leveldb/database/iterator.rs.html#137-150 ?

jszwedko added a commit to vectordotdev/vector that referenced this issue Jul 30, 2021
blt pushed a commit to vectordotdev/vector that referenced this issue Aug 3, 2021
dbcfd pushed a commit to dbcfd/vector that referenced this issue Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants