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

Method load_cache

nodedb/src/control/array_sync/ack_registry.rs:133–178  ·  view source on GitHub ↗
(db: &Database)

Source from the content-addressed store, hash-verified

131 }
132
133 fn load_cache(db: &Database) -> crate::Result<HashMap<String, AckVector>> {
134 let txn = db.begin_read().map_err(|e| crate::Error::Storage {
135 engine: "array_sync".into(),
136 detail: format!("ack_registry load begin_read: {e}"),
137 })?;
138 let table = txn
139 .open_table(ACK_TABLE)
140 .map_err(|e| crate::Error::Storage {
141 engine: "array_sync".into(),
142 detail: format!("ack_registry load open_table: {e}"),
143 })?;
144
145 let mut cache: HashMap<String, AckVector> = HashMap::new();
146 let iter = table.iter().map_err(|e| crate::Error::Storage {
147 engine: "array_sync".into(),
148 detail: format!("ack_registry load iter: {e}"),
149 })?;
150
151 for entry in iter {
152 let (k, v) = entry.map_err(|e| crate::Error::Storage {
153 engine: "array_sync".into(),
154 detail: format!("ack_registry load entry: {e}"),
155 })?;
156 let key = k.value();
157 let val = v.value();
158
159 let Some(array) = array_from_key(key) else {
160 warn!("ack_registry: malformed key, skipping");
161 continue;
162 };
163 let Some(replica_raw) = replica_id_from_key(key) else {
164 warn!(array = %array, "ack_registry: cannot parse replica_id, skipping");
165 continue;
166 };
167 if val.len() != 18 {
168 warn!(array = %array, "ack_registry: ack hlc wrong length, skipping");
169 continue;
170 }
171 let hlc_bytes: [u8; 18] = val.try_into().unwrap_or([0u8; 18]);
172 let hlc = Hlc::from_bytes(&hlc_bytes);
173 let replica_id = ReplicaId::new(replica_raw);
174 cache.entry(array).or_default().record(replica_id, hlc);
175 }
176
177 Ok(cache)
178 }
179
180 /// Record an ack from `replica_id` for `array` at `ack_hlc`.
181 ///

Callers

nothing calls this directly

Calls 6

array_from_keyFunction · 0.85
replica_id_from_keyFunction · 0.85
entryMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45
recordMethod · 0.45

Tested by

no test coverage detected