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

Method checkpoint_to_bytes

nodedb-graph/src/csr/persist.rs:60–92  ·  view source on GitHub ↗

Serialize the index to rkyv bytes (with magic header) for storage. # Errors Returns [`GraphError::MemoryBudget`] if a memory governor is installed and the serialization buffer would exceed the `Graph` engine budget.

(&self)

Source from the content-addressed store, hash-verified

58 /// Returns [`GraphError::MemoryBudget`] if a memory governor is installed
59 /// and the serialization buffer would exceed the `Graph` engine budget.
60 pub fn checkpoint_to_bytes(&self) -> Result<Vec<u8>, GraphError> {
61 let snapshot = CsrSnapshotRkyv {
62 nodes: self.id_to_node.clone(),
63 labels: self.id_to_label.clone(),
64 out_offsets: self.out_offsets.clone(),
65 out_targets: self.out_targets.to_vec(),
66 out_labels: self.out_labels.to_vec(),
67 in_offsets: self.in_offsets.clone(),
68 in_targets: self.in_targets.to_vec(),
69 in_labels: self.in_labels.to_vec(),
70 buffer_out: self.buffer_out.clone(),
71 buffer_in: self.buffer_in.clone(),
72 deleted: self.deleted_edges.iter().copied().collect(),
73 has_weights: self.has_weights,
74 out_weights: self.out_weights.as_ref().map(|w| w.to_vec()),
75 in_weights: self.in_weights.as_ref().map(|w| w.to_vec()),
76 buffer_out_weights: self.buffer_out_weights.clone(),
77 buffer_in_weights: self.buffer_in_weights.clone(),
78 };
79 let rkyv_bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&snapshot)
80 .expect("CSR rkyv serialization should not fail");
81 let buf_capacity = RKYV_MAGIC.len() + 1 + rkyv_bytes.len();
82 let _budget_guard = self
83 .governor
84 .as_ref()
85 .map(|g| g.reserve(EngineId::Graph, buf_capacity * size_of::<u8>()))
86 .transpose()?;
87 let mut buf = Vec::with_capacity(buf_capacity);
88 buf.extend_from_slice(RKYV_MAGIC);
89 buf.push(CSR_FORMAT_VERSION);
90 buf.extend_from_slice(&rkyv_bytes);
91 Ok(buf)
92 }
93
94 /// Restore an index from a checkpoint snapshot.
95 ///

Calls 9

collectMethod · 0.80
cloneMethod · 0.45
to_vecMethod · 0.45
iterMethod · 0.45
as_refMethod · 0.45
expectMethod · 0.45
lenMethod · 0.45
reserveMethod · 0.45
pushMethod · 0.45