Skip to content

Commit b986e7d

Browse files
authored
Allow combining different stores (#2489)
* Create skeleton of a combinator to use different stores based on the root key. * Implement the remaining functions
1 parent a65dd25 commit b986e7d

File tree

4 files changed

+514
-1
lines changed

4 files changed

+514
-1
lines changed

linera-storage/src/db_storage.rs

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use linera_execution::{
2121
WasmRuntime,
2222
};
2323
use linera_views::{
24+
backends::dual::{DualStoreRootKeyAssignment, StoreInUse},
2425
batch::Batch,
2526
common::KeyValueStore,
2627
context::ViewContext,
@@ -227,6 +228,20 @@ enum BaseKey {
227228
BlobState(BlobId),
228229
}
229230

231+
/// An implementation of [`DualStoreRootKeyAssignment`] that stores the
232+
/// chain states into the first store.
233+
pub struct ChainStatesFirstAssignment;
234+
235+
impl DualStoreRootKeyAssignment for ChainStatesFirstAssignment {
236+
fn assigned_store(root_key: &[u8]) -> Result<StoreInUse, bcs::Error> {
237+
let store = match bcs::from_bytes(root_key)? {
238+
BaseKey::ChainState(_) => StoreInUse::First,
239+
_ => StoreInUse::Second,
240+
};
241+
Ok(store)
242+
}
243+
}
244+
230245
/// A `Clock` implementation using the system clock.
231246
#[derive(Clone)]
232247
pub struct WallClock;

linera-storage/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use linera_views::{
3737

3838
#[cfg(with_testing)]
3939
pub use crate::db_storage::TestClock;
40-
pub use crate::db_storage::{DbStorage, WallClock};
40+
pub use crate::db_storage::{ChainStatesFirstAssignment, DbStorage, WallClock};
4141
#[cfg(with_metrics)]
4242
pub use crate::db_storage::{
4343
READ_CERTIFICATE_COUNTER, READ_HASHED_CERTIFICATE_VALUE_COUNTER, WRITE_CERTIFICATE_COUNTER,

0 commit comments

Comments
 (0)