| 202 | // ─── Internal helpers ───────────────────────────────────────────────────── |
| 203 | |
| 204 | fn persist(&self, array: &str, schema_hlc: Hlc, loro_snapshot: Vec<u8>) -> crate::Result<()> { |
| 205 | let persisted = PersistedSchema { |
| 206 | replica_id: self.replica_id.as_u64(), |
| 207 | schema_hlc_bytes: schema_hlc.to_bytes().to_vec(), |
| 208 | loro_snapshot, |
| 209 | }; |
| 210 | let bytes = zerompk::to_msgpack_vec(&persisted).map_err(|e| Error::Storage { |
| 211 | engine: "array_sync".into(), |
| 212 | detail: format!("schema_registry persist encode '{array}': {e}"), |
| 213 | })?; |
| 214 | |
| 215 | let txn = self.db.begin_write().map_err(|e| Error::Storage { |
| 216 | engine: "array_sync".into(), |
| 217 | detail: format!("schema_registry persist begin_write '{array}': {e}"), |
| 218 | })?; |
| 219 | { |
| 220 | let mut table = txn.open_table(SCHEMA_DOCS).map_err(|e| Error::Storage { |
| 221 | engine: "array_sync".into(), |
| 222 | detail: format!("schema_registry persist open_table '{array}': {e}"), |
| 223 | })?; |
| 224 | table |
| 225 | .insert(array.as_bytes(), bytes.as_slice()) |
| 226 | .map_err(|e| Error::Storage { |
| 227 | engine: "array_sync".into(), |
| 228 | detail: format!("schema_registry persist insert '{array}': {e}"), |
| 229 | })?; |
| 230 | } |
| 231 | txn.commit().map_err(|e| Error::Storage { |
| 232 | engine: "array_sync".into(), |
| 233 | detail: format!("schema_registry persist commit '{array}': {e}"), |
| 234 | }) |
| 235 | } |
| 236 | |
| 237 | fn load_all( |
| 238 | db: &Database, |