-
Notifications
You must be signed in to change notification settings - Fork 38
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
Feat: implement in-memory KVStorage #61
Feat: implement in-memory KVStorage #61
Conversation
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.
What happend to test_suite
?
kv-storage/src/memory.rs
Outdated
type DB = HashMap<Hash256, Vec<u8>>; | ||
|
||
#[derive(Clone)] | ||
pub struct IMDB { |
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.
Let's use MemoryDB
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.
Fixed.
kv-storage/src/memory.rs
Outdated
|
||
type DB = HashMap<Hash256, Vec<u8>>; |
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.
Snapshot
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.
Fixed.
kv-storage/src/memory.rs
Outdated
|
||
#[derive(Clone)] | ||
pub struct IMDB { | ||
db: 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.
current_revision
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.
Fixed.
kv-storage/src/memory.rs
Outdated
impl KVStorage for IMDB { | ||
async fn commit_checkpoint(&mut self) -> Result<(), Error> { | ||
self.checkpoint = self.db.clone(); | ||
|
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.
Please remove the new line
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.
Fixed.
kv-storage/src/memory.rs
Outdated
} | ||
|
||
async fn get(&self, key: Hash256) -> Result<Vec<u8>, Error> { | ||
match self.db.get(&key) { |
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.
ditto.
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.
ditto
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.
Fixed.
kv-storage/src/memory.rs
Outdated
} | ||
|
||
async fn contain(&self, key: Hash256) -> Result<bool, Error> { | ||
match self.db.get(&key) { |
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.
ditto.
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.
For the similar reason with async fn remove
, cannot implement that way.
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.
Fixed.
kv-storage/src/memory.rs
Outdated
} | ||
|
||
async fn remove(&mut self, key: Hash256) -> Result<(), Error> { | ||
match self.db.remove(&key) { |
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.
Let's use https://doc.rust-lang.org/std/option/enum.Option.html#method.ok_or for the simplicity
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.
Cannot implement using ok_or
since HashMap::remove
returns Option<Vec<u8>>
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.
Fixed.
kv-storage/src/memory.rs
Outdated
|
||
async fn revert_to_latest_checkpoint(&mut self) -> Result<(), Error> { | ||
self.db = self.checkpoint.clone(); | ||
|
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.
ditto.
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.
Fixed.
kv-storage/src/memory.rs
Outdated
|
||
async fn insert_or_update(&mut self, key: Hash256, value: &[u8]) -> Result<(), Error> { | ||
self.db.insert(key, value.to_vec()); | ||
|
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.
ditto.
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.
Fixed.
cf0c1f1
to
c156993
Compare
Closes #58