MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / restore_core_state

Function restore_core_state

nodedb/src/storage/snapshot_executor.rs:136–161  ·  view source on GitHub ↗

Restore a single core's engine state from a `CoreSnapshot`. Opens the core's redb databases, clears existing data, and loads the snapshot data. Returns `(documents_count, vectors_count)`.

(
    data_dir: &Path,
    core_id: usize,
    snap: &CoreSnapshot,
)

Source from the content-addressed store, hash-verified

134/// Opens the core's redb databases, clears existing data, and loads
135/// the snapshot data. Returns `(documents_count, vectors_count)`.
136fn restore_core_state(
137 data_dir: &Path,
138 core_id: usize,
139 snap: &CoreSnapshot,
140) -> crate::Result<(u64, u64)> {
141 let sparse_path = data_dir.join(format!("sparse/core-{core_id}.redb"));
142 if let Some(parent) = sparse_path.parent() {
143 // no-objectstore: redb opens a local file directly; warm-tier blob is restored, this is the engine-state landing path.
144 std::fs::create_dir_all(parent).map_err(crate::Error::Io)?;
145 }
146 let sparse = crate::engine::sparse::btree::SparseEngine::open(&sparse_path)?;
147 restore_sparse_data(&sparse, &snap.sparse_documents, &snap.sparse_indexes)?;
148
149 let graph_path = data_dir.join(format!("graph/core-{core_id}.redb"));
150 if let Some(parent) = graph_path.parent() {
151 // no-objectstore: redb opens a local file directly; engine-state landing path.
152 std::fs::create_dir_all(parent).map_err(crate::Error::Io)?;
153 }
154 let edge_store = crate::engine::graph::edge_store::store::EdgeStore::open(&graph_path)?;
155 restore_edge_data(&edge_store, &snap.edges)?;
156
157 let vectors = restore_vector_checkpoints(data_dir, core_id, &snap.hnsw_indexes)?;
158 restore_crdt_checkpoints(data_dir, core_id, &snap.crdt_snapshots)?;
159
160 Ok((snap.sparse_documents.len() as u64, vectors))
161}
162
163fn restore_sparse_data(
164 sparse: &crate::engine::sparse::btree::SparseEngine,

Callers 1

execute_restoreFunction · 0.85

Calls 7

restore_sparse_dataFunction · 0.85
restore_edge_dataFunction · 0.85
restore_crdt_checkpointsFunction · 0.85
joinMethod · 0.80
openFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected