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

Method checkpoint_vector_indexes

nodedb/src/data/executor/vector_checkpoint.rs:58–100  ·  view source on GitHub ↗

Write HNSW checkpoints for all vector indexes to disk. Called periodically from the TPC event loop (e.g., every 5 minutes or when idle). Each index is serialized to a file at `{data_dir}/vector-ckpt/{index_key}.ckpt`. After checkpointing, WAL replay only needs to process entries since the checkpoint — not the entire history.

(&self)

Source from the content-addressed store, hash-verified

56 /// After checkpointing, WAL replay only needs to process entries
57 /// since the checkpoint — not the entire history.
58 pub fn checkpoint_vector_indexes(&self) -> usize {
59 if self.vector_collections.is_empty() {
60 return 0;
61 }
62
63 let ckpt_dir = self.data_dir.join("vector-ckpt");
64 if std::fs::create_dir_all(&ckpt_dir).is_err() {
65 tracing::warn!(
66 core = self.core_id,
67 "failed to create vector checkpoint dir"
68 );
69 return 0;
70 }
71
72 let mut checkpointed = 0;
73 for (key, collection) in &self.vector_collections {
74 if collection.is_empty() {
75 continue;
76 }
77 let bytes = collection.checkpoint_to_bytes(self.vector_checkpoint_kek.as_ref());
78 if bytes.is_empty() {
79 continue;
80 }
81 // Checkpoint filename uses the old-style `"{tid}:{coll}"` form so
82 // existing on-disk checkpoint files remain valid across upgrades.
83 let filename = CoreLoop::vector_checkpoint_filename(key);
84 let ckpt_path = ckpt_dir.join(format!("{filename}.ckpt"));
85 let tmp_path = ckpt_dir.join(format!("{filename}.ckpt.tmp"));
86 if nodedb_wal::segment::atomic_write_fsync(&tmp_path, &ckpt_path, &bytes).is_ok() {
87 checkpointed += 1;
88 }
89 }
90
91 if checkpointed > 0 {
92 tracing::info!(
93 core = self.core_id,
94 checkpointed,
95 total = self.vector_collections.len(),
96 "vector collections checkpointed"
97 );
98 }
99 checkpointed
100 }
101
102 /// Load HNSW checkpoints from disk on startup, before WAL replay.
103 ///

Callers 3

spawn_coreFunction · 0.80
execute_checkpointMethod · 0.80
maybe_run_maintenanceMethod · 0.80

Calls 6

atomic_write_fsyncFunction · 0.85
joinMethod · 0.80
is_okMethod · 0.80
is_emptyMethod · 0.45
checkpoint_to_bytesMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected