MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / import_snapshot

Method import_snapshot

nodedb/src/control/array_sync/schema_registry.rs:104–133  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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.

Callers 2

load_allMethod · 0.45
handle_schemaMethod · 0.45

Calls 5

lockMethod · 0.80
entryMethod · 0.80
schema_hlcMethod · 0.45
export_snapshotMethod · 0.45
persistMethod · 0.45

Tested by

no test coverage detected