-
Notifications
You must be signed in to change notification settings - Fork 51
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
perf(rocksdb): ⚡ Better use of Rocksdb multiget and batch writes #86
Merged
Conversation
This file contains 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
jbcaron
approved these changes
Apr 29, 2024
@@ -10,17 +9,17 @@ impl BlockHashView { | |||
pub fn insert(&mut self, block_number: u64, block_hash: &Felt252Wrapper) -> Result<(), DeoxysStorageError> { | |||
let db = DeoxysBackend::expose_db(); | |||
let column = db.get_column(Column::BlockNumberToHash); | |||
db.put_cf(&column, block_number.encode(), block_hash.encode()) | |||
db.put_cf(&column, bincode::serialize(&block_number).unwrap(), bincode::serialize(&block_hash).unwrap()) |
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 create new Storage error for serialize and deserialize
pub fn get_at( | ||
pub fn get_nonce(self, contract_address: &ContractAddress) -> Result<Option<Nonce>, DeoxysStorageError> { | ||
self.get(contract_address) | ||
.map(|option| option.map(|contract_data| contract_data.nonce.get().cloned().unwrap_or_default())) |
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.
use as_ref()
instead of cloned()
antiyro
approved these changes
Apr 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request type
Please add the labels corresponding to the type of changes your PR introduces:
What is the current behavior?
Our current usage of rocksdb heavily parallelises database read and write operations when commiting. This is not necessarily more efficient, as rocsdkb has it's own capabilities for retrieving and writing multiple values from and to the database.
What is the new behavior?
Made better use of rocksdb multiget and batch writes. Storage handler
commit
operations are now synchronous. Note that each commit is still run inside a separate task which is joined as this still provides better performance, but the commit operation itself is synchronous. Seestorage_update.rs
for more information.Changes were also made to the data serialization model, with
bincode
now being the primary method of serialization overparity-scale-codec
. Changes have also been made toStorageContractData
to avoid the usage of binary trees to store class hash and nonce history, preferring instead our own revertibleHistory<T>
implementation. This should also have the effect of reducing storage in this area. New accessors were also added to simply retrieving the nonce and class hash as compared to before.Work was also done refactoring primitive types
StorageContractData
andStorageContractClassData
. These have been moved fromcarates/primitives
to a newclient/db/src/storage_handler/primitives
folder. Please place any struct used as a storage wrapper here in the future.Does this introduce a breaking change?
Yes. Due to change in storage, nodes already running will have to restart synchronizing from block 0.