store: move all capnp code to capnp.rs
Consolidate capnp serialization in one place: - capnp_enum! and capnp_message! macros - read_text/read_uuid helpers - Type-to-capnp mappings - from_capnp_migrate migration impls types.rs now only has pure Rust types and helpers. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
e48ca2ecad
commit
ba53597cf2
5 changed files with 229 additions and 211 deletions
|
|
@ -7,9 +7,9 @@
|
|||
// redb provides indexed access; Store struct holds in-memory state.
|
||||
//
|
||||
// Module layout:
|
||||
// types.rs — Node, Relation, enums, capnp macros, path helpers
|
||||
// types.rs — Node, Relation, enums, path/time helpers
|
||||
// capnp.rs — serialization macros, log IO (load, replay, append, fsck)
|
||||
// index.rs — redb index operations
|
||||
// capnp.rs — capnp log IO (load, replay, append, fsck)
|
||||
// ops.rs — mutations (upsert, delete, rename, etc.)
|
||||
// view.rs — StoreView trait for read-only access
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ mod view;
|
|||
pub use types::{
|
||||
memory_dir, nodes_path,
|
||||
now_epoch, epoch_to_local, format_date, format_datetime, format_datetime_space, compact_timestamp, today,
|
||||
Node, Relation, NodeType, RelationType, Store,
|
||||
Node, Relation, NodeType, RelationType,
|
||||
new_node, new_relation,
|
||||
};
|
||||
pub use view::StoreView;
|
||||
|
|
@ -32,6 +32,7 @@ pub use ops::current_provenance;
|
|||
|
||||
use crate::graph::{self, Graph};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
/// Strip .md suffix from a key, handling both bare keys and section keys.
|
||||
|
|
@ -45,6 +46,31 @@ pub fn strip_md_suffix(key: &str) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
// The full in-memory store
|
||||
pub struct Store {
|
||||
pub nodes: HashMap<String, Node>, // key → latest node
|
||||
pub uuid_to_key: HashMap<[u8; 16], String>, // uuid → key (rebuilt from nodes)
|
||||
pub relations: Vec<Relation>, // all active relations
|
||||
/// Log sizes at load time — used for staleness detection.
|
||||
pub(crate) loaded_nodes_size: u64,
|
||||
pub(crate) loaded_rels_size: u64,
|
||||
/// redb index database
|
||||
pub(crate) db: Option<redb::Database>,
|
||||
}
|
||||
|
||||
impl Default for Store {
|
||||
fn default() -> Self {
|
||||
Store {
|
||||
nodes: HashMap::new(),
|
||||
uuid_to_key: HashMap::new(),
|
||||
relations: Vec::new(),
|
||||
loaded_nodes_size: 0,
|
||||
loaded_rels_size: 0,
|
||||
db: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Store {
|
||||
pub fn build_graph(&self) -> Graph {
|
||||
graph::build_graph(self)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue