-
Notifications
You must be signed in to change notification settings - Fork 244
kvdb-rocksdb: pass ReadOptions to iterators #277
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb88d20
kvdb-rocksdb: pass ReadOptions to iterators
ordian 18811bc
kvdb-rocksdb: add some iter docs
ordian b428c3c
Apply David's suggestions from code review
ordian b2c1dff
Merge branch 'master' into ao-pass-read-option-to-prefix-iter
ordian 429a02d
kvdb-rocksdb: postprocess docs
ordian cb94d4f
Merge branch 'master' into ao-pass-read-option-to-prefix-iter
dvdplm 9c59871
formatting
dvdplm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,15 @@ | |
| //! This module contains an implementation of a RocksDB iterator | ||
| //! wrapped inside a `RwLock`. Since `RwLock` "owns" the inner data, | ||
| //! we're using `owning_ref` to work around the borrowing rules of Rust. | ||
| //! | ||
| //! Note, that we're not using "Prefix Seek" mode, so that the prefix iterator will return | ||
| //! keys not starting with the given prefix as well, and we need to filter them | ||
|
ordian marked this conversation as resolved.
Outdated
|
||
| //! out manually. See https://github.com/facebook/rocksdb/wiki/Prefix-Seek-API-Changes | ||
|
ordian marked this conversation as resolved.
Outdated
|
||
|
|
||
| use crate::DBAndColumns; | ||
| use owning_ref::{OwningHandle, StableAddress}; | ||
| use parking_lot::RwLockReadGuard; | ||
| use rocksdb::{DBIterator, IteratorMode}; | ||
| use rocksdb::{DBIterator, Direction, IteratorMode, ReadOptions}; | ||
| use std::ops::{Deref, DerefMut}; | ||
|
|
||
| /// A tuple holding key and value data, used as the iterator item type. | ||
|
|
@@ -76,22 +80,31 @@ pub trait IterationHandler { | |
|
|
||
| /// Create an `Iterator` over the default DB column or over a `ColumnFamily` if a column number | ||
| /// is passed. | ||
| fn iter(&self, col: Option<u32>) -> Self::Iterator; | ||
| fn iter(&self, col: Option<u32>, read_opts: &ReadOptions) -> Self::Iterator; | ||
| /// Create an `Iterator` over the default DB column or over a `ColumnFamily` if a column number | ||
| /// is passed. The iterator starts from the first key having the provided `prefix`. | ||
| fn iter_from_prefix(&self, col: Option<u32>, prefix: &[u8]) -> Self::Iterator; | ||
| fn iter_from_prefix(&self, col: Option<u32>, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator; | ||
| } | ||
|
|
||
| impl<'a, T> ReadGuardedIterator<'a, <&'a T as IterationHandler>::Iterator, T> | ||
| where | ||
| &'a T: IterationHandler, | ||
| { | ||
| pub fn new(read_lock: RwLockReadGuard<'a, Option<T>>, col: Option<u32>) -> Self { | ||
| Self { inner: Self::new_inner(read_lock, |db| db.iter(col)) } | ||
| /// Maps `RwLock<RocksDB>` to `RwLock<DBIterator>`, where | ||
|
ordian marked this conversation as resolved.
Outdated
|
||
| /// `DBIterator` iterates over all keys. | ||
|
ordian marked this conversation as resolved.
Outdated
|
||
| pub fn new(read_lock: RwLockReadGuard<'a, Option<T>>, col: Option<u32>, read_opts: &ReadOptions) -> Self { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
…and there are other methods that now take |
||
| Self { inner: Self::new_inner(read_lock, |db| db.iter(col, read_opts)) } | ||
| } | ||
|
|
||
| pub fn new_from_prefix(read_lock: RwLockReadGuard<'a, Option<T>>, col: Option<u32>, prefix: &[u8]) -> Self { | ||
| Self { inner: Self::new_inner(read_lock, |db| db.iter_from_prefix(col, prefix)) } | ||
| /// Maps `RwLock<RocksDB>` to `RwLock<DBIterator>`, where | ||
| /// `DBIterator` iterates over keys >= prefix. | ||
| pub fn new_from_prefix( | ||
|
ordian marked this conversation as resolved.
|
||
| read_lock: RwLockReadGuard<'a, Option<T>>, | ||
| col: Option<u32>, | ||
| prefix: &[u8], | ||
| read_opts: &ReadOptions, | ||
| ) -> Self { | ||
| Self { inner: Self::new_inner(read_lock, |db| db.iter_from_prefix(col, prefix, read_opts)) } | ||
| } | ||
|
|
||
| fn new_inner( | ||
|
|
@@ -108,21 +121,25 @@ where | |
| impl<'a> IterationHandler for &'a DBAndColumns { | ||
| type Iterator = DBIterator<'a>; | ||
|
|
||
| fn iter(&self, col: Option<u32>) -> Self::Iterator { | ||
| fn iter(&self, col: Option<u32>, read_opts: &ReadOptions) -> Self::Iterator { | ||
| col.map_or_else( | ||
| || self.db.iterator(IteratorMode::Start), | ||
| || self.db.iterator_opt(IteratorMode::Start, read_opts), | ||
| |c| { | ||
| self.db | ||
| .iterator_cf(self.get_cf(c as usize), IteratorMode::Start) | ||
| .iterator_cf_opt(self.get_cf(c as usize), read_opts, IteratorMode::Start) | ||
| .expect("iterator params are valid; qed") | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| fn iter_from_prefix(&self, col: Option<u32>, prefix: &[u8]) -> Self::Iterator { | ||
| fn iter_from_prefix(&self, col: Option<u32>, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator { | ||
| col.map_or_else( | ||
| || self.db.prefix_iterator(prefix), | ||
| |c| self.db.prefix_iterator_cf(self.get_cf(c as usize), prefix).expect("iterator params are valid; qed"), | ||
| || self.db.iterator_opt(IteratorMode::From(prefix, Direction::Forward), read_opts), | ||
| |c| { | ||
| self.db | ||
| .iterator_cf_opt(self.get_cf(c as usize), read_opts, IteratorMode::From(prefix, Direction::Forward)) | ||
| .expect("iterator params are valid; qed") | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.