-
Notifications
You must be signed in to change notification settings - Fork 246
[kvdb-rocksdb] switch to upstream #257
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 all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
215a28d
Switch from `parity-rocksdb` to upstream `rust-rocksdb`
bkchr 2c0468f
wip
ordian d445cde
wip
ordian 2d42479
Merge branch 'master' into ao-rocksdb-switch-to-upstream2
ordian 47a6e22
kvdb-rocksdb: working iterator
ordian 81bce7c
kvdb-rocksdb: cleanup
ordian 71b2af0
kvdb-rocksdb: more cleanup
ordian e5cd5cb
kvdb-rocksdb: use options from updated upstream
ordian c7640d1
kvdb-rocksdb: set bloom filter as recommended by tuning guide
ordian fb208ad
kvdb-rocksdb: fix build
ordian 8a2442a
kvdb-rocksdb: set_level_compaction_dynamic_level_bytes
ordian fa16fb5
kvdb-rocksdb: switch to just published version
ordian 3b31e4f
kvdb-rocksdb: preserve the old compression_per_level setting
ordian f595233
kvdb-rocksdb: add some iter module docs
ordian df8d614
kvdb-rocksdb: remove path on kvdb dependency temporarily
ordian a479485
kvdb-rocksdb: use only lz4 and snappy features
ordian 1e1a865
Merge branch 'master' into ao-rocksdb-switch-to-upstream2
ordian 3153cca
kvdb-rocksdb: support zstd compression as well
ordian ed372f4
Also add `kvdb` as path dependency
bkchr 28de430
Apply suggestions from code review
ordian d978759
kvdb-rocksdb: fix build
ordian 9adccb8
Merge branch 'master' into ao-rocksdb-switch-to-upstream2
ordian 13b029c
kvdb-rocksdb: use open_cf_descriptors
ordian c88186f
kvdb-rocksdb: remove redundant .into()
ordian 03a2ba0
Disable `zstd` again
bkchr 407c604
kvdb-rocksdb: set block_size to 64 KB again
ordian 1739d8a
kvdb-rocksdb: cargo fmt
ordian 8c658ba
kvdb-rocksdb: set back block_size to 16 KB
ordian 87d0aec
moar cargo fmt
ordian 3a071af
Add tests for budget calculation
dvdplm cd343cc
Add test to check the rocksdb settings
dvdplm 7eeaf7b
kvdb-rocksdb: do not account for default column memory budget
ordian bd5abf1
kvdb-rocksdb: please the CI
ordian f23574f
kvdb-rocksdb: remove lz4 feature as it has no effect for now
ordian 8986947
Merge branch 'master' into ao-rocksdb-switch-to-upstream2
ordian 6a64e36
Address review grumbles
dvdplm 15af306
Merge branch 'ao-rocksdb-switch-to-upstream2' of github.com:paritytec…
dvdplm 0217438
kvdb-rocksdb: add failing iter_from_prefix test
ordian e0d59e5
kvdb-rocksdb: add a workaround for the rocksdb prefix bug
ordian c4b5413
More prefix iter test
dvdplm adde7df
Merge branch 'ao-rocksdb-switch-to-upstream2' of github.com:paritytec…
dvdplm b40b416
Fix tests (hex, it's so hard)
dvdplm 38876cf
whitespace
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
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 |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // Copyright 2019 Parity Technologies (UK) Ltd. | ||
| // This file is part of Parity. | ||
|
|
||
| // Parity is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Parity is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! 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. | ||
|
|
||
| use crate::DBAndColumns; | ||
| use owning_ref::{OwningHandle, StableAddress}; | ||
| use parking_lot::RwLockReadGuard; | ||
| use rocksdb::{DBIterator, IteratorMode}; | ||
| use std::ops::{Deref, DerefMut}; | ||
|
|
||
| /// A tuple holding key and value data, used as the iterator item type. | ||
| pub type KeyValuePair = (Box<[u8]>, Box<[u8]>); | ||
|
|
||
| /// Iterator with built-in synchronization. | ||
| pub struct ReadGuardedIterator<'a, I, T> { | ||
| inner: OwningHandle<UnsafeStableAddress<'a, Option<T>>, DerefWrapper<Option<I>>>, | ||
| } | ||
|
|
||
| // We can't implement `StableAddress` for a `RwLockReadGuard` | ||
| // directly due to orphan rules. | ||
| #[repr(transparent)] | ||
| struct UnsafeStableAddress<'a, T>(RwLockReadGuard<'a, T>); | ||
|
|
||
| impl<'a, T> Deref for UnsafeStableAddress<'a, T> { | ||
| type Target = T; | ||
| fn deref(&self) -> &Self::Target { | ||
| self.0.deref() | ||
| } | ||
| } | ||
|
|
||
| // RwLockReadGuard dereferences to a stable address; qed | ||
| unsafe impl<'a, T> StableAddress for UnsafeStableAddress<'a, T> {} | ||
|
|
||
| struct DerefWrapper<T>(T); | ||
|
|
||
| impl<T> Deref for DerefWrapper<T> { | ||
| type Target = T; | ||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl<T> DerefMut for DerefWrapper<T> { | ||
| fn deref_mut(&mut self) -> &mut Self::Target { | ||
| &mut self.0 | ||
| } | ||
| } | ||
|
|
||
| impl<'a, I: Iterator, T> Iterator for ReadGuardedIterator<'a, I, T> { | ||
| type Item = I::Item; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| self.inner.deref_mut().as_mut().and_then(|iter| iter.next()) | ||
| } | ||
| } | ||
|
|
||
| /// Instantiate iterators yielding `KeyValuePair`s. | ||
| pub trait IterationHandler { | ||
| type Iterator: Iterator<Item = KeyValuePair>; | ||
|
|
||
| /// 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; | ||
| /// 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; | ||
| } | ||
|
|
||
| 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)) } | ||
| } | ||
|
|
||
| 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)) } | ||
| } | ||
|
|
||
| fn new_inner( | ||
| rlock: RwLockReadGuard<'a, Option<T>>, | ||
| f: impl FnOnce(&'a T) -> <&'a T as IterationHandler>::Iterator, | ||
| ) -> OwningHandle<UnsafeStableAddress<'a, Option<T>>, DerefWrapper<Option<<&'a T as IterationHandler>::Iterator>>> { | ||
| OwningHandle::new_with_fn(UnsafeStableAddress(rlock), move |rlock| { | ||
| let rlock = unsafe { rlock.as_ref().expect("initialized as non-null; qed") }; | ||
| DerefWrapper(rlock.as_ref().map(f)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl<'a> IterationHandler for &'a DBAndColumns { | ||
| type Iterator = DBIterator<'a>; | ||
|
|
||
| fn iter(&self, col: Option<u32>) -> Self::Iterator { | ||
| col.map_or_else( | ||
| || self.db.iterator(IteratorMode::Start), | ||
| |c| { | ||
| self.db | ||
| .iterator_cf(self.get_cf(c as usize), IteratorMode::Start) | ||
| .expect("iterator params are valid; qed") | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| fn iter_from_prefix(&self, col: Option<u32>, prefix: &[u8]) -> 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"), | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some documentation would be nice :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trait was originally added in #120, we can remove it and all generics here, but it's good to have if we will consider merging something similar to #120.
Another idea I had is replace
RwLock<Option<DBAndColumns>>with https://docs.rs/arc-swap/0.4.4/arc_swap/, but let's keep it as is for now.