Load HNSW checkpoints from disk on startup, before WAL replay. For each checkpoint file, loads the index. WAL replay then only needs to process entries after the checkpoint LSN.
(&mut self)
| 104 | /// For each checkpoint file, loads the index. WAL replay then only |
| 105 | /// needs to process entries after the checkpoint LSN. |
| 106 | pub fn load_vector_checkpoints(&mut self) { |
| 107 | let ckpt_dir = self.data_dir.join("vector-ckpt"); |
| 108 | if !ckpt_dir.exists() { |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | let entries = match std::fs::read_dir(&ckpt_dir) { |
| 113 | Ok(e) => e, |
| 114 | Err(_) => return, |
| 115 | }; |
| 116 | |
| 117 | let mut loaded = 0; |
| 118 | for entry in entries.flatten() { |
| 119 | let path = entry.path(); |
| 120 | if path.extension().and_then(|e| e.to_str()) != Some("ckpt") { |
| 121 | continue; |
| 122 | } |
| 123 | |
| 124 | // Checkpoint filenames are `"{tid}:{coll}.ckpt"` — parse back to tuple. |
| 125 | let filename = path |
| 126 | .file_stem() |
| 127 | .and_then(|s| s.to_str()) |
| 128 | .unwrap_or("") |
| 129 | .to_string(); |
| 130 | if filename.is_empty() { |
| 131 | continue; |
| 132 | } |
| 133 | let tuple_key = parse_build_key(&filename); |
| 134 | |
| 135 | let Ok(bytes) = nodedb_wal::segment::read_checkpoint_dontneed(&path) else { |
| 136 | continue; |
| 137 | }; |
| 138 | let kek = self.vector_checkpoint_kek.as_ref(); |
| 139 | let load_result = |
| 140 | crate::engine::vector::collection::VectorCollection::from_checkpoint(&bytes, kek); |
| 141 | let collection = match load_result { |
| 142 | Ok(Some(c)) => c, |
| 143 | Ok(None) => continue, |
| 144 | Err(e) => { |
| 145 | tracing::warn!( |
| 146 | core = self.core_id, |
| 147 | key = %filename, |
| 148 | error = %e, |
| 149 | "vector checkpoint rejected" |
| 150 | ); |
| 151 | continue; |
| 152 | } |
| 153 | }; |
| 154 | tracing::info!( |
| 155 | core = self.core_id, |
| 156 | key = %filename, |
| 157 | vectors = collection.len(), |
| 158 | "loaded vector checkpoint" |
| 159 | ); |
| 160 | self.vector_collections.insert(tuple_key, collection); |
| 161 | loaded += 1; |
| 162 | } |
| 163 |
no test coverage detected