Skip to content

Commit

Permalink
refactor(store): improve DualStore configuration and documentation (#127
Browse files Browse the repository at this point in the history
)

- 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
appcypher authored Feb 5, 2025
1 parent e29b236 commit a4c955b
Show file tree
Hide file tree
Showing 6 changed files with 412 additions and 52 deletions.
4 changes: 2 additions & 2 deletions monofs/lib/store/flatfsstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ where
}

// Create CID and store the block
let cid = monoutils_store::make_cid(Codec::DagCbor, &bytes);
let cid = monoutils_store::generate_cid(Codec::DagCbor, &bytes);
let block_path = self.get_block_path(&cid);

if !block_path.exists() {
Expand Down Expand Up @@ -570,7 +570,7 @@ where
}
}

let cid = monoutils_store::make_cid(Codec::Raw, bytes.as_ref());
let cid = monoutils_store::generate_cid(Codec::Raw, bytes.as_ref());
let block_path = self.get_block_path(&cid);

if !block_path.exists() {
Expand Down
120 changes: 120 additions & 0 deletions monofs/lib/store/layeredstore.rs
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
// }
// }
Loading

0 comments on commit a4c955b

Please sign in to comment.