-
Notifications
You must be signed in to change notification settings - Fork 218
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
kvdb: no overlay #313
kvdb: no overlay #313
Conversation
/// written can always be read, but may be present in an in-memory buffer. Values which have | ||
/// been flushed have been moved to backing storage, like a RocksDB instance. There are certain | ||
/// operations which are only guaranteed to operate on flushed data and not buffered, | ||
/// although implementations may differ in this regard. |
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.
Anyone who relies on this semantics shouldn't have done it on the first place, it is not written anywhere (is it?)
@NikVolf ^^^ :P
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 is probably about iterators? :)
I wonder if we can get rid of locks on |
I considered using https://docs.rs/arc-swap/0.4.4/arc_swap/, but |
pub fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>> { | ||
self.iter_from_prefix(col, prefix).next().map(|(_, v)| v) | ||
} | ||
|
||
/// Get database iterator for flushed data. |
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.
it was probably lying before?
since it was interleaved with actual data?
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.
partially, I guess
in order to support non-flushed data properly, it would have to take flushing
into account (see e.g. get
)
Let's move this conversation to #314. |
Great stuff! |
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.
Code looks great, a significant cleanup. I haven't read the audit yet so I'll be back with a proper review.
pub fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option<Box<[u8]>> { | ||
self.iter_from_prefix(col, prefix).next().map(|(_, v)| v) | ||
} | ||
|
||
/// Get database iterator for flushed data. | ||
/// Get database iterator for the data. | ||
/// Will hold a lock until the iterator is dropped | ||
/// preventing the database from being closed. |
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.
I've probably asked this before, apologies, but why is it bad to close the DB while some thread is iterating over data? Is the assumption that threads iterating over some data must be allowed to complete?
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 is a good question, but I consider it to be part of the #314
kvdb/src/lib.rs
Outdated
@@ -118,25 +109,16 @@ pub trait KeyValueDB: Sync + Send + parity_util_mem::MallocSizeOf { | |||
/// Get a value by key. | |||
fn get(&self, col: u32, key: &[u8]) -> io::Result<Option<DBValue>>; | |||
|
|||
/// Get a value by partial key. Only works for flushed data. | |||
/// Get a value by partial key. Only works for the data. |
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.
/// Get a value by partial key. Only works for the data. | |
/// Get the first value matching the given prefix. |
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.
Is it first or any random value?
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.
First in the current implementation and I think we're relying on that, but maybe I'm wrong
fn iter<'a>(&'a self, col: u32) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>; | ||
|
||
/// Iterate over flushed data for a given column, starting from a given prefix. | ||
/// Iterate over the data for a given column, starting from a given prefix. | ||
fn iter_from_prefix<'a>( |
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.
maybe we want to finally rename it, but let's do it in a separate PR
Co-Authored-By: David <dvdplm@gmail.com>
* master: keccak-hash: switch benches to criterion (#315)
So, any progress on this? I'd love to see some benchmarks on both eth and substrate before moving ahead. |
* master: Add different mode for malloc_size_of_is_0 macro dealing with generics (#334) [parity-crypto] Use upstream secp256k1 (#258) Bump parking_lot to 0.10 and minor versions (#332) Remove libc completely (#333) update changelogs (#329) bump parity-util-mem to 0.4.2 (#328) remove libc feature from fixed-hash (#317) kvdb-rocksdb: release 0.4.2 (#327) kvdb-rocksdb: fix iter_from_prefix being slow (#326) MallocSizeOf for BTreeSet (#325) split off primitives (#323) travis: disable kvdb-web tests for chrome (#324) Expand const fn coverage (#319) uint: make zero const fn (#318) README: fix appveyor badge (#316)
I did import benchmarks on eth side #310 (comment), but we currently lack some read-heavy benches like RPC load etc. Would be nice if someone could bench it in substrate as well. |
* master: prepare rlp-derive release (#344) Update/change licenses: MIT/Apache2.0 (#342) rlp-derive extracted (#343) Format for readme and changelog corrected (#341) Parity runtime moved to parity common for publication in crates.io (#271) Disable cache if explicit memory budget=0 passed (#339) [parity-crypto] prepare 0.5.0 (#336) [parity crypto]: remove unused depend `rustc_hex` (#337) Update doc comment (#335)
Getting back to this, since substrate doesn't use @dvdplm let me know what you think |
I really like this PR and I want it to land, but I still want to be convinced we have hard data to support the decision. |
See #310 (comment) about eth usage of it. |
Oops, apologies. K, fine let's do this then. :) |
* master: kvdb-rocksdb: optimize and rename iter_from_prefix (#365) bump parity-util-mem (#376) parity-util-mem: fix for windows (#375) keccak-hash: fix bench and add one for range (#372) [parity-crypto] Release 0.6.1 (#373) keccak-hash: bump version to 0.5.1 (#371) keccak-hash: add keccak256_range and keccak512_range functions (#370) Allow pubkey recovery for all-zero messages (#369) Delete by prefix operator in kvdb (#360) kvdb: no overlay (#313) Ban duplicates of parity-uil-mem from being linked into the same program (#363) Use correct license ID (#362) Memtest example for Rocksdb (#349) Prep for release (#361) parity-util-mem: prepare release for 0.5.2 (#359) travis: test parity-util-mem on android (#358) parity-util-mem: update mimalloc feature (#352) kvdb: remove parity-bytes dependency (#351) parity-util-mem: use malloc for usable_size on android (#355) CI: troubleshoot macOS build (#356)
* master: (56 commits) primitive-types: add no_std support for serde feature (#385) Add Rocksdb Secondary Instance Api (#384) kvdb-rocksdb: update rocksdb to 0.14 (#379) prepare releases for a few crates (#382) uint: fix UB in uint::from_big_endian (#381) Fix limit prefix delete case (#368) Add arbitrary trait implementation (#378) kvdb-rocksdb: optimize and rename iter_from_prefix (#365) bump parity-util-mem (#376) parity-util-mem: fix for windows (#375) keccak-hash: fix bench and add one for range (#372) [parity-crypto] Release 0.6.1 (#373) keccak-hash: bump version to 0.5.1 (#371) keccak-hash: add keccak256_range and keccak512_range functions (#370) Allow pubkey recovery for all-zero messages (#369) Delete by prefix operator in kvdb (#360) kvdb: no overlay (#313) Ban duplicates of parity-uil-mem from being linked into the same program (#363) Use correct license ID (#362) Memtest example for Rocksdb (#349) ...
Fixes #310.