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

Adapting to Conflux storage interface: Implement get_state method for LvmtStore #22

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lvmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod amt_change_manager;
mod auth_changes;
pub mod crypto;
mod example;
mod snapshot;
mod storage;
pub mod table_schema;
#[cfg(test)]
Expand Down
33 changes: 33 additions & 0 deletions src/lvmt/snapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::{
errors::Result,
middlewares::{
table_schema::{KeyValueSnapshotRead, VersionedKeyValueSchema},
CommitID,
},
traits::KeyValueStoreManager,
};

use super::{storage::LvmtStore, table_schema::FlatKeyValue};

pub struct LvmtSnapshot<'db> {
key_value_view: Box<KeyValueSnapshotRead<'db, FlatKeyValue>>,
}

impl<'cache, 'db> LvmtStore<'cache, 'db> {
pub fn get_state(&self, commit: CommitID) -> Result<LvmtSnapshot> {
let key_value_view = self.get_key_value_store().get_versioned_store(&commit)?;

Ok(LvmtSnapshot {
key_value_view: Box::new(key_value_view),
})
}
}

impl<'db> LvmtSnapshot<'db> {
pub fn get(
&self,
key: &<FlatKeyValue as VersionedKeyValueSchema>::Key,
) -> Result<Option<<FlatKeyValue as VersionedKeyValueSchema>::Value>> {
self.key_value_view.get(key)
}
}
5 changes: 4 additions & 1 deletion src/lvmt/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,17 @@ fn allocate_version_slot(
}
}

#[cfg(test)]
impl<'cache, 'db> LvmtStore<'cache, 'db> {
pub fn get_key_value_store(&self) -> &VersionedStore<'cache, 'db, FlatKeyValue> {
&self.key_value_store
}

#[cfg(test)]
pub fn get_amt_node_store(&self) -> &VersionedStore<'cache, 'db, AmtNodes> {
&self.amt_node_store
}

#[cfg(test)]
pub fn get_slot_alloc_store(&self) -> &VersionedStore<'cache, 'db, SlotAllocations> {
&self.slot_alloc_store
}
Expand Down
Loading