Apply a remote Loro snapshot for `array`. Creates the entry if absent. Persists the updated snapshot.
(
&self,
array: &str,
snapshot_bytes: &[u8],
remote_hlc: Hlc,
)
| 102 | /// |
| 103 | /// Creates the entry if absent. Persists the updated snapshot. |
| 104 | pub fn import_snapshot( |
| 105 | &self, |
| 106 | array: &str, |
| 107 | snapshot_bytes: &[u8], |
| 108 | remote_hlc: Hlc, |
| 109 | ) -> crate::Result<()> { |
| 110 | let mut docs = self.docs.lock().map_err(|_| Error::Storage { |
| 111 | engine: "array_sync".into(), |
| 112 | detail: "schema_registry lock poisoned".into(), |
| 113 | })?; |
| 114 | |
| 115 | let doc = docs |
| 116 | .entry(array.to_owned()) |
| 117 | .or_insert_with(|| SchemaDoc::new(self.replica_id)); |
| 118 | |
| 119 | doc.import_snapshot(snapshot_bytes, remote_hlc, &self.hlc_gen) |
| 120 | .map_err(|e| Error::Storage { |
| 121 | engine: "array_sync".into(), |
| 122 | detail: format!("schema_registry import_snapshot '{array}': {e}"), |
| 123 | })?; |
| 124 | |
| 125 | let schema_hlc = doc.schema_hlc(); |
| 126 | let snapshot = doc.export_snapshot().map_err(|e| Error::Storage { |
| 127 | engine: "array_sync".into(), |
| 128 | detail: format!("schema_registry export after import '{array}': {e}"), |
| 129 | })?; |
| 130 | drop(docs); |
| 131 | |
| 132 | self.persist(array, schema_hlc, snapshot) |
| 133 | } |
| 134 | |
| 135 | /// Apply a Raft-committed Loro snapshot for `array`, preserving the exact |
| 136 | /// committed HLC on every replica. |
no test coverage detected