-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(store): improve DualStore configuration and documentation (#127
) - Improved DualStore configuration with separate read_from and write_to options - Added comprehensive documentation and examples for DualStore - Added extensive test coverage for DualStore operations - Renamed data parameter to node in IpldStore trait for consistency - Added StoreConfig trait for configurable stores - Updated Codec enum to handle unknown values - Renamed make_cid to generate_cid for better semantic clarity
- Loading branch information
Showing
6 changed files
with
412 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
use std::{collections::HashSet, pin::Pin}; | ||
|
||
use async_trait::async_trait; | ||
use bytes::Bytes; | ||
use monoutils_store::{ | ||
ipld::cid::Cid, Codec, DualStore, DualStoreConfig, IpldReferences, IpldStore, MemoryStore, | ||
RawStore, StoreResult, | ||
}; | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
use tokio::io::AsyncRead; | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
// Types: LayeredStore | ||
//-------------------------------------------------------------------------------------------------- | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct LayeredStore<S> | ||
where | ||
S: IpldStore, | ||
{ | ||
inner: LayeredStoreInner<S>, | ||
} | ||
|
||
struct LayeredStoreInner<S> | ||
where | ||
S: IpldStore, | ||
{ | ||
write_store: S, | ||
base_store: S, | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
// Methods: MemoryBufferStore | ||
//-------------------------------------------------------------------------------------------------- | ||
|
||
impl<S> MemoryBufferStore<S> | ||
where | ||
S: IpldStore, | ||
{ | ||
/// Creates a new `MemoryBufferStore` with the given backup store. | ||
pub fn new(backup_store: S) -> Self { | ||
Self { | ||
inner: DualStore::new( | ||
MemoryStore::default(), | ||
backup_store, | ||
DualStoreConfig::default(), | ||
), | ||
} | ||
} | ||
} | ||
|
||
// //-------------------------------------------------------------------------------------------------- | ||
// // Trait Implementations | ||
// //-------------------------------------------------------------------------------------------------- | ||
|
||
// #[async_trait] | ||
// impl<S> IpldStore for MemoryBufferStore<S> | ||
// where | ||
// S: IpldStore + Sync, | ||
// { | ||
// async fn put_node<T>(&self, data: &T) -> StoreResult<Cid> | ||
// where | ||
// T: Serialize + IpldReferences + Sync, | ||
// { | ||
// self.inner.put_node(data).await | ||
// } | ||
|
||
// async fn put_bytes(&self, reader: impl AsyncRead + Send + Sync) -> StoreResult<Cid> { | ||
// self.inner.put_bytes(reader).await | ||
// } | ||
|
||
// async fn get_node<T>(&self, cid: &Cid) -> StoreResult<T> | ||
// where | ||
// T: DeserializeOwned + Send, | ||
// { | ||
// self.inner.get_node(cid).await | ||
// } | ||
|
||
// async fn get_bytes(&self, cid: &Cid) -> StoreResult<Pin<Box<dyn AsyncRead + Send>>> { | ||
// self.inner.get_bytes(cid).await | ||
// } | ||
|
||
// async fn get_bytes_size(&self, cid: &Cid) -> StoreResult<u64> { | ||
// self.inner.get_bytes_size(cid).await | ||
// } | ||
|
||
// async fn has(&self, cid: &Cid) -> bool { | ||
// self.inner.has(cid).await | ||
// } | ||
|
||
// async fn get_supported_codecs(&self) -> HashSet<Codec> { | ||
// self.inner.get_supported_codecs().await | ||
// } | ||
|
||
// async fn get_max_node_block_size(&self) -> StoreResult<Option<u64>> { | ||
// self.inner.get_max_node_block_size().await | ||
// } | ||
|
||
// async fn get_block_count(&self) -> StoreResult<u64> { | ||
// self.inner.get_block_count().await | ||
// } | ||
// } | ||
|
||
// #[async_trait] | ||
// impl<S> RawStore for MemoryBufferStore<S> | ||
// where | ||
// S: IpldStore + Sync, | ||
// { | ||
// async fn put_raw_block(&self, bytes: impl Into<Bytes> + Send) -> StoreResult<Cid> { | ||
// self.inner.put_raw_block(bytes).await | ||
// } | ||
|
||
// async fn get_raw_block(&self, cid: &Cid) -> StoreResult<Bytes> { | ||
// self.inner.get_raw_block(cid).await | ||
// } | ||
|
||
// async fn get_max_raw_block_size(&self) -> StoreResult<Option<u64>> { | ||
// self.inner.get_max_raw_block_size().await | ||
// } | ||
// } |
Oops, something went wrong.