Return the snapshot with the highest HLC for `array`, or `None` if none exist.
(&self, array: &str)
| 165 | |
| 166 | /// Return the snapshot with the highest HLC for `array`, or `None` if none exist. |
| 167 | pub fn latest_for_array(&self, array: &str) -> Option<TileSnapshot> { |
| 168 | let prefix = name_prefix(array)?; |
| 169 | let txn = self.db.begin_read().ok()?; |
| 170 | let table = txn.open_table(SNAPSHOT_TABLE).ok()?; |
| 171 | |
| 172 | // Scan the full range and collect prefix-matched keys; last = latest HLC. |
| 173 | let iter = table.iter().ok()?; |
| 174 | let mut last_bytes: Option<Vec<u8>> = None; |
| 175 | for entry in iter { |
| 176 | let Ok((k, v)) = entry else { |
| 177 | continue; |
| 178 | }; |
| 179 | let key = k.value(); |
| 180 | if key.starts_with(prefix.as_slice()) { |
| 181 | last_bytes = Some(v.value().to_vec()); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | let bytes = last_bytes?; |
| 186 | decode_snapshot(&bytes) |
| 187 | .map_err(|e| { |
| 188 | warn!(array = %array, error = %e, "snapshot_store: decode error on latest"); |
| 189 | }) |
| 190 | .ok() |
| 191 | } |
| 192 | |
| 193 | /// Delete all snapshots for `array` whose `snapshot_hlc < older_than`. |
| 194 | /// |