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

Streamline kvdb API and upgrade rocksdb to 0.19 #661

Merged
merged 12 commits into from
Aug 15, 2022
Merged

Conversation

ordian
Copy link
Member

@ordian ordian commented Aug 14, 2022

The rocksdb upgrade seems non-breaking, but it uses tikv-jemalloc-sys transitively which links to the native library jemalloc.
It's about time we release a new version of each crate anyway.

Depends on: #662.

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aboard to update these deps but it looks like the API for rocksdb::DBIterator has changed to Result<Option<_>> which needs to fixed in order to compile

@ordian
Copy link
Member Author

ordian commented Aug 14, 2022

Yup, submitted a PR too quickly, but in the process of fixing this realized how to remove owning_ref and simplify the code 💡
After submitting the PR, will fix this one.

@ordian ordian force-pushed the ao-upgrade-rocksdb branch from eeebcee to 2ff8f23 Compare August 14, 2022 13:25
@ordian ordian marked this pull request as ready for review August 14, 2022 13:25
@ordian
Copy link
Member Author

ordian commented Aug 14, 2022

The compilation fix is in 2957b4e An alternative would be to change the kvdb to have Item = DBResult<KeyValuePair> in order to propagate the error to the caller.

I don't have a strong preference between these two.

@cheme
Copy link
Collaborator

cheme commented Aug 14, 2022

Could also consider changing kvdb trait.
get return io_result, get_by_prefix does not, iter does not, maybe all should return result (even iterator step), I think it is the case on parity_db.
(could be part of #661)

kvdb-rocksdb/src/lib.rs Outdated Show resolved Hide resolved
@dvdplm
Copy link
Contributor

dvdplm commented Aug 15, 2022

Can you rebase now that #662 is merged for easier reviewing?

@ordian
Copy link
Member Author

ordian commented Aug 15, 2022

Could also consider changing kvdb trait. get return io_result, get_by_prefix does not, iter does not, maybe all should return result (even iterator step), I think it is the case on parity_db. (could be part of #661)

Thanks for this. I was not sure whether to make more breaking changes or keep as is: #661 (comment), but I think having an iterator API that swallows errors might be a bad design and it's better to let the use bail out ASAP if needed (I imagine that'd be the default). Will make those changes to kvdb to streamline the API as well.

@cheme
Copy link
Collaborator

cheme commented Aug 15, 2022

Could also consider changing kvdb trait. get return io_result, get_by_prefix does not, iter does not, maybe all should return result (even iterator step), I think it is the case on parity_db. (could be part of #661)

Thanks for this. I was not sure whether to make more breaking changes or keep as is: #661 (comment), but I think having an iterator API that swallows errors might be a bad design and it's better to let the use bail out ASAP if needed (I imagine that'd be the default). Will make those changes to kvdb to streamline the API as well.

yes this https://github.com/paritytech/polkadot/blob/0879bdbcd93ae96602d42e1c2f9fd54c752eace5/node/subsystem-util/src/database.rs#L147 was me being lazy to change the trait, seeing that rocksdb deps also return result, changing trait sounds right to me.

@ordian ordian force-pushed the ao-upgrade-rocksdb branch from d8b659f to 62535e1 Compare August 15, 2022 10:03
@ordian
Copy link
Member Author

ordian commented Aug 15, 2022

Could also consider changing kvdb trait. get return io_result, get_by_prefix does not, iter does not, maybe all should return result (even iterator step), I think it is the case on parity_db. (could be part of #661)

Thanks for this. I was not sure whether to make more breaking changes or keep as is: #661 (comment), but I think having an iterator API that swallows errors might be a bad design and it's better to let the use bail out ASAP if needed (I imagine that'd be the default). Will make those changes to kvdb to streamline the API as well.

yes this https://github.com/paritytech/polkadot/blob/0879bdbcd93ae96602d42e1c2f9fd54c752eace5/node/subsystem-util/src/database.rs#L147 was me being lazy to change the trait, seeing that rocksdb deps also return result, changing trait sounds right to me.

I don't blame you here. As you can see I was hesitant to make these breaking changes here myself. We need to improve our release and upgrade process so people are less afraid of making breaking changes.

Updated the PR, please take a look.

kvdb/src/lib.rs Outdated Show resolved Hide resolved
@ordian ordian changed the title upgrade kvdb to 0.19 and tikv-jemallocator to 0.5 Streamline kvdb API and upgrade rocksdb to 0.19 Aug 15, 2022
@ordian
Copy link
Member Author

ordian commented Aug 15, 2022

Can you rebase now that #662 is merged for easier reviewing?

@dvdplm Could you take a look please?

@ordian ordian requested a review from niklasad1 August 15, 2022 12:48
@@ -144,8 +146,8 @@ pub trait KeyValueDB: Sync + Send + parity_util_mem::MallocSizeOf {
}

/// Check for the existence of a value by prefix.
fn has_prefix(&self, col: u32, prefix: &[u8]) -> bool {
self.get_by_prefix(col, prefix).is_some()
fn has_prefix(&self, col: u32, prefix: &[u8]) -> io::Result<bool> {
Copy link
Member

@niklasad1 niklasad1 Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether folks care about whether the key was not found or an error occurred.... i.e, you could convert both Option::None and Result:Error to false

Further it also possible use get_by_prefix if one wants to know the cause..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but it was also inconsistent with has_key method. I believe we should try to report the IO error to the user as soon as it happens and not swallow it in the lib. It might make it less ergonomic, but with ? shouldn't be much of a problem.

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicely done, looks good to me I had a couple optional minor comments...

@ordian ordian merged commit 26d712d into master Aug 15, 2022
@ordian ordian deleted the ao-upgrade-rocksdb branch August 15, 2022 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants