Skip to content

Commit

Permalink
Allow combining different stores (#2489)
Browse files Browse the repository at this point in the history
* Create skeleton of a combinator to use different stores based on the root key.

* Implement the remaining functions
  • Loading branch information
ma2bd authored Sep 23, 2024
1 parent a65dd25 commit b986e7d
Show file tree
Hide file tree
Showing 4 changed files with 514 additions and 1 deletion.
15 changes: 15 additions & 0 deletions linera-storage/src/db_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use linera_execution::{
WasmRuntime,
};
use linera_views::{
backends::dual::{DualStoreRootKeyAssignment, StoreInUse},
batch::Batch,
common::KeyValueStore,
context::ViewContext,
Expand Down Expand Up @@ -227,6 +228,20 @@ enum BaseKey {
BlobState(BlobId),
}

/// An implementation of [`DualStoreRootKeyAssignment`] that stores the
/// chain states into the first store.
pub struct ChainStatesFirstAssignment;

impl DualStoreRootKeyAssignment for ChainStatesFirstAssignment {
fn assigned_store(root_key: &[u8]) -> Result<StoreInUse, bcs::Error> {
let store = match bcs::from_bytes(root_key)? {
BaseKey::ChainState(_) => StoreInUse::First,
_ => StoreInUse::Second,
};
Ok(store)
}
}

/// A `Clock` implementation using the system clock.
#[derive(Clone)]
pub struct WallClock;
Expand Down
2 changes: 1 addition & 1 deletion linera-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use linera_views::{

#[cfg(with_testing)]
pub use crate::db_storage::TestClock;
pub use crate::db_storage::{DbStorage, WallClock};
pub use crate::db_storage::{ChainStatesFirstAssignment, DbStorage, WallClock};
#[cfg(with_metrics)]
pub use crate::db_storage::{
READ_CERTIFICATE_COUNTER, READ_HASHED_CERTIFICATE_VALUE_COUNTER, WRITE_CERTIFICATE_COUNTER,
Expand Down
Loading

0 comments on commit b986e7d

Please sign in to comment.