tawasuyu

tawasuyu/brahman

Rust 326TOML 123JSON 17Markdown 144606 Definitions

⎇ d3649bfd1a80153652c2a028315369bb4b184024 crates/modules/semantic_dht/minga-store/src/repo.rs Rust · 41 lines · 1.2 KB History Who touched what raw

chore: monorepo inicial con arje + minga + yahweh absorbidos 53dbdf0f1 · Sergio ·

1//! `PersistentRepo`: agrupa los tres stores (nodos, atestaciones, MST)
2//! sobre una única `sled::Db`. Cada store ocupa su propio tree
3//! (namespace lógico) dentro del mismo directorio en disco.
4
5use std::path::Path;
6
7use sled::Db;
8
9use crate::{
10    attestation_store::SledAttestationStore, error::StoreError, mst_store::SledMstStore,
11    node_store::SledNodeStore,
12};
13
14pub struct PersistentRepo {
15    db: Db,
16    pub nodes: SledNodeStore,
17    pub attestations: SledAttestationStore,
18    pub mst: SledMstStore,
19}
20
21impl PersistentRepo {
22    pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, StoreError> {
23        let db = sled::open(path)?;
24        let nodes = SledNodeStore::open_tree(&db, "nodes")?;
25        let attestations = SledAttestationStore::open_tree(&db, "attestations")?;
26        let mst = SledMstStore::open_tree(&db, "mst")?;
27        Ok(Self {
28            db,
29            nodes,
30            attestations,
31            mst,
32        })
33    }
34
35    /// Flushea los tres trees a disco. Llamar en puntos de
36    /// checkpoint o antes de cerrar para garantizar durabilidad.
37    pub fn flush(&self) -> Result<(), StoreError> {
38        self.db.flush()?;
39        Ok(())
40    }
41}