(
db: &Database,
_replica_id: ReplicaId,
hlc_gen: &Arc<HlcGenerator>,
)
| 235 | } |
| 236 | |
| 237 | fn load_all( |
| 238 | db: &Database, |
| 239 | _replica_id: ReplicaId, |
| 240 | hlc_gen: &Arc<HlcGenerator>, |
| 241 | ) -> crate::Result<HashMap<String, SchemaDoc>> { |
| 242 | let txn = db.begin_read().map_err(|e| Error::Storage { |
| 243 | engine: "array_sync".into(), |
| 244 | detail: format!("schema_registry load_all begin_read: {e}"), |
| 245 | })?; |
| 246 | let table = txn.open_table(SCHEMA_DOCS).map_err(|e| Error::Storage { |
| 247 | engine: "array_sync".into(), |
| 248 | detail: format!("schema_registry load_all open_table: {e}"), |
| 249 | })?; |
| 250 | |
| 251 | let mut docs = HashMap::new(); |
| 252 | let iter = table.iter().map_err(|e| Error::Storage { |
| 253 | engine: "array_sync".into(), |
| 254 | detail: format!("schema_registry load_all iter: {e}"), |
| 255 | })?; |
| 256 | |
| 257 | for entry in iter { |
| 258 | let (k, v) = entry.map_err(|e| Error::Storage { |
| 259 | engine: "array_sync".into(), |
| 260 | detail: format!("schema_registry load_all entry: {e}"), |
| 261 | })?; |
| 262 | let name = match std::str::from_utf8(k.value()) { |
| 263 | Ok(s) => s.to_owned(), |
| 264 | Err(e) => { |
| 265 | warn!(error = %e, "schema_registry: skipping non-UTF8 key"); |
| 266 | continue; |
| 267 | } |
| 268 | }; |
| 269 | let persisted: PersistedSchema = match zerompk::from_msgpack(v.value()) { |
| 270 | Ok(p) => p, |
| 271 | Err(e) => { |
| 272 | warn!(name, error = %e, "schema_registry: skipping corrupt schema entry"); |
| 273 | continue; |
| 274 | } |
| 275 | }; |
| 276 | let hlc_arr: [u8; 18] = match persisted.schema_hlc_bytes.try_into() { |
| 277 | Ok(a) => a, |
| 278 | Err(v) => { |
| 279 | warn!( |
| 280 | name, |
| 281 | len = v.len(), |
| 282 | "schema_registry: skipping entry with wrong hlc_bytes length" |
| 283 | ); |
| 284 | continue; |
| 285 | } |
| 286 | }; |
| 287 | let schema_hlc = Hlc::from_bytes(&hlc_arr); |
| 288 | let mut doc = SchemaDoc::new(ReplicaId::new(persisted.replica_id)); |
| 289 | if let Err(e) = doc.import_snapshot(&persisted.loro_snapshot, schema_hlc, hlc_gen) { |
| 290 | warn!(name, error = %e, "schema_registry: skipping corrupt loro snapshot"); |
| 291 | continue; |
| 292 | } |
| 293 | docs.insert(name, doc); |
| 294 | } |
nothing calls this directly
no test coverage detected