Export the current state of all engines into a serializable snapshot. This captures the complete Data Plane state for this core: redb tables (sparse + edge), in-memory HNSW indexes, and CRDT state.
(&self)
| 10 | /// This captures the complete Data Plane state for this core: |
| 11 | /// redb tables (sparse + edge), in-memory HNSW indexes, and CRDT state. |
| 12 | pub fn export_snapshot(&self) -> crate::Result<crate::data::snapshot::CoreSnapshot> { |
| 13 | use crate::data::snapshot::*; |
| 14 | |
| 15 | let sparse_documents: Vec<KvPair> = self |
| 16 | .sparse |
| 17 | .export_documents()? |
| 18 | .into_iter() |
| 19 | .map(|(k, v)| KvPair { key: k, value: v }) |
| 20 | .collect(); |
| 21 | |
| 22 | let sparse_indexes: Vec<KvPair> = self |
| 23 | .sparse |
| 24 | .export_indexes()? |
| 25 | .into_iter() |
| 26 | .map(|(k, v)| KvPair { key: k, value: v }) |
| 27 | .collect(); |
| 28 | |
| 29 | let edges: Vec<TenantKvPair> = self |
| 30 | .edge_store |
| 31 | .export_edges()? |
| 32 | .into_iter() |
| 33 | .map(|(tid, k, v)| TenantKvPair { |
| 34 | tenant_id: tid.as_u64(), |
| 35 | key: k, |
| 36 | value: v, |
| 37 | }) |
| 38 | .collect(); |
| 39 | |
| 40 | let hnsw_indexes: Vec<HnswSnapshot> = self |
| 41 | .vector_collections |
| 42 | .iter() |
| 43 | .filter_map(|(key, coll)| { |
| 44 | let checkpoint_bytes = |
| 45 | coll.checkpoint_to_bytes(self.vector_checkpoint_kek.as_ref()); |
| 46 | if checkpoint_bytes.is_empty() { |
| 47 | return None; |
| 48 | } |
| 49 | Some(HnswSnapshot { |
| 50 | tenant_id: key.0.as_u64(), |
| 51 | collection: key.1.clone(), |
| 52 | checkpoint_bytes, |
| 53 | }) |
| 54 | }) |
| 55 | .collect(); |
| 56 | |
| 57 | let crdt_snapshots: Vec<CrdtSnapshot> = self |
| 58 | .crdt_engines |
| 59 | .iter() |
| 60 | .map(|(tid, engine)| { |
| 61 | Ok(CrdtSnapshot { |
| 62 | tenant_id: tid.as_u64(), |
| 63 | peer_id: engine.peer_id(), |
| 64 | snapshot_bytes: engine.export_snapshot_bytes()?, |
| 65 | }) |
| 66 | }) |
| 67 | .collect::<crate::Result<Vec<_>>>()?; |
| 68 | |
| 69 | Ok(CoreSnapshot { |
no test coverage detected