-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Added the actual implementation for the AtomicView::latest_view
#1994
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fea24a3
Extract `HistoricalView` trait from the `AtomicView`
xgreenx 4c20273
Updated changelog
xgreenx 5119dbe
Removed not related code to the chagne
xgreenx 4b3aecb
Fixed tests
xgreenx b06c622
Fixed the column
xgreenx 61f1059
Move all functionality from the `Database` to the views
xgreenx c5ec5bf
Moved `latest_height` to `HistoricalView` trait
xgreenx db90520
Merge branch 'refs/heads/feature/historical-view-trait' into feature/…
xgreenx 2b9eadc
Improved readability
xgreenx c61477f
Merge branch 'refs/heads/master' into feature/iteratable-view
xgreenx c3d6f66
Merge branch 'master' into feature/iteratable-view
xgreenx 29d543e
Updated CHANGELOG.md
xgreenx 682d256
Simplify imports
xgreenx 11d1d28
Make CI happy
xgreenx 187ec91
Added the actual implementation for the `AtomicView::latest_view`
xgreenx ec86d61
Updated CHANGELOG.md
xgreenx 22f6a63
Merge branch 'master' into feature/iteratable-view
xgreenx 46d0eca
Merge branch 'master' into feature/iteratable-view
xgreenx 19f7433
Merge branch 'feature/iteratable-view' into feature/atomic-latest-view
xgreenx f642a4a
Simplify signature of the constracutor
xgreenx c9f4ca2
Merge branch 'refs/heads/feature/iteratable-view' into feature/atomic…
xgreenx 58c698e
Renamed `IterableView` into `IterableKeyValueView`
xgreenx d5b6535
Renamed `IterableView` to `IterableKeyValueView`
xgreenx 0bf402b
Merge branch 'refs/heads/feature/iteratable-view' into feature/atomic…
xgreenx 97983c5
Merge branch 'refs/heads/master' into feature/atomic-latest-view
xgreenx 8513901
Use explicit getter instead of deref
xgreenx 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// TODO: Move the implementation from the module to here. | ||
pub mod memory_store; | ||
pub mod memory_view; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::database::database_description::{ | ||
on_chain::OnChain, | ||
DatabaseDescription, | ||
}; | ||
use fuel_core_storage::{ | ||
iter::{ | ||
iterator, | ||
BoxedIter, | ||
IntoBoxedIter, | ||
IterDirection, | ||
IterableStore, | ||
}, | ||
kv_store::{ | ||
KVItem, | ||
KeyValueInspect, | ||
StorageColumn, | ||
Value, | ||
}, | ||
transactional::ReferenceBytesKey, | ||
Result as StorageResult, | ||
}; | ||
use std::collections::BTreeMap; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct MemoryView<Description = OnChain> | ||
where | ||
Description: DatabaseDescription, | ||
{ | ||
pub(crate) inner: Vec<BTreeMap<ReferenceBytesKey, Value>>, | ||
pub(crate) _marker: core::marker::PhantomData<Description>, | ||
} | ||
|
||
impl<Description> MemoryView<Description> | ||
where | ||
Description: DatabaseDescription, | ||
{ | ||
pub fn iter_all<'a>( | ||
&'a self, | ||
column: Description::Column, | ||
prefix: Option<&[u8]>, | ||
start: Option<&[u8]>, | ||
direction: IterDirection, | ||
) -> impl Iterator<Item = KVItem> + 'a { | ||
let btree = &self.inner[column.as_usize()]; | ||
|
||
iterator(btree, prefix, start, direction) | ||
.map(|(key, value)| (key.clone().into(), value.clone())) | ||
.map(Ok) | ||
} | ||
} | ||
|
||
impl<Description> KeyValueInspect for MemoryView<Description> | ||
where | ||
Description: DatabaseDescription, | ||
{ | ||
type Column = Description::Column; | ||
|
||
fn get(&self, key: &[u8], column: Self::Column) -> StorageResult<Option<Value>> { | ||
Ok(self.inner[column.as_usize()].get(key).cloned()) | ||
} | ||
} | ||
|
||
impl<Description> IterableStore for MemoryView<Description> | ||
where | ||
Description: DatabaseDescription, | ||
{ | ||
fn iter_store( | ||
&self, | ||
column: Self::Column, | ||
prefix: Option<&[u8]>, | ||
start: Option<&[u8]>, | ||
direction: IterDirection, | ||
) -> BoxedIter<KVItem> { | ||
self.iter_all(column, prefix, start, direction).into_boxed() | ||
} | ||
} |
Oops, something went wrong.
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.
Can we explain in the
expect
why we assume this isn't poisoned? I'm curious, but it's also best practice.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.
The code below works in the same way=D We could replace it with another lock that doesn't require expect in a separate RP.
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.
That would be even better than what I suggested.