-
Notifications
You must be signed in to change notification settings - Fork 627
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
[store] Introduce Flat store adapter #12123
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12123 +/- ##
==========================================
+ Coverage 71.51% 71.59% +0.07%
==========================================
Files 820 822 +2
Lines 165037 165176 +139
Branches 165037 165176 +139
==========================================
+ Hits 118034 118261 +227
+ Misses 41864 41782 -82
+ Partials 5139 5133 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
} | ||
} | ||
|
||
pub trait StoreAdapter { |
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 like the fact store_helpers
is gone 👍
IMO there's something off with the new API
StoreAdapter
having a method flat_store()
and at the same time introducing aFlatStoreAdapter
implementation of StoreAdapter
sounds confusing. It feels like the separation is not at the right place.
Should we take a step back and reason about the core idea?
Do we want to hide "flat storage", "memtries", etc behind an easy to use interface or do we want them to be concrete implementation of a more general "store"? Right now I see an implementation for the former with some sprinkles of the latter.
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.
Aah right, that can definitely sound confusing but the idea is to have inter convertibility among all the adapter types. For example if I have an epoch_store_adapter, flat_store_adapter, trie_store_adapter, chain_store_adapter.... I should be able to call xxx_store_adapter.flat_store() to get an instance of flat_store_adapter
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.
Flat storage and memtries are to remain as they are right now, this store abstraction is at a much much lower level, right above rocks db.
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.
(fyi flat_store
may sound confusing, I didn't have a better name, but it doesn't refer to FlatStorage
, but just a wrapper on top of store
)
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.
ahah I see thanks!
On this point do you already know where should flat_store be used vs epoch_store or trie_store..? Does it simply depend on the type of columns to read/write?
I'm wondering if rather than an true adapter suite we are looking for a wrapper around Store (doesn't have to be a trait)?
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.
Umm yeah, there are high level patterns in our codebase (with LOT of exceptions). It should be possible to categorize the store and store update interface needs based on where it's used, like the trie_store, epoch_store etc. etc. that I mentioned. Yes, it does depend on the location/module where it's used and the set of columns it needs to access.
This is pretty much like a wrapper around Store :)
I wasn't in favor of using traits as with real structs, we have the option to store tiny pieces of data that maybe beneficial, say like a cache.
It may explicitly be useful for our resharding case where we need to map the child shard_uid to parent shard_uid. This can seamlessly be done within the trie_store and trie_store_update structs with just one additional store read! @staffik for context
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.
Sorry, to be clear, while StoreAdapter
is definitely a trait that provides us the inter-convertibility between different types of adapters, the explicit adapters themselves, like FlatStoreAdapter
are structs (they could have as well been traits)
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.
@Trisfald Shreyan and I went through a couple of alternative designs and unfortunately given all the issues with these alternatives it seems the one used in the PR is still relatively the best. I'm a Rust perfectionist and I don't like how this is designed, but practicality is more important I guess.
How does the composing the updates work across adapters and base traits? For example, finalizing a block will generate a large transaction with updates to different parts of the DB. Some of these updates will be for flat store (using |
While I don't specifically know about ChainStoreUpdate and how that's structured, high level, yes, once we have a store_update object, it's simple to convert it to a mutable reference of any type of update adapter, i.e. If you take a look at |
|
||
// Static instances of StoreUpdateHolder always hold an owned StoreUpdate instance. | ||
// In such case it should be possible to convert it to StoreUpdate. | ||
impl Into<StoreUpdate> for StoreUpdateHolder<'static> { |
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.
😬
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.
Oh well...
} | ||
} | ||
|
||
pub trait StoreAdapter { |
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.
@Trisfald Shreyan and I went through a couple of alternative designs and unfortunately given all the issues with these alternatives it seems the one used in the PR is still relatively the best. I'm a Rust perfectionist and I don't like how this is designed, but practicality is more important I guess.
Follow up on #12123 This PR replaces `ReadOnlyChunksStore` with `ChunkStoreAdapter`.
PR in the series to move to store adapter. Follow up on #12123
This is the first concept PR of having adapters on top of store. Most of the details for how it works can be found in core/store/src/adapter/mod.rs
The functions in core/store/src/adapter/flat_store.rs are moved from store_helper file.