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

Method recover

nodedb/src/wal/audit_segment.rs:105–132  ·  view source on GitHub ↗

Replay all audit WAL entries for crash recovery. Returns `(data_lsn, audit_entry_bytes)` pairs in LSN order. The caller deserializes the audit entry bytes and rebuilds the in-memory cache.

(&self)

Source from the content-addressed store, hash-verified

103 /// Returns `(data_lsn, audit_entry_bytes)` pairs in LSN order.
104 /// The caller deserializes the audit entry bytes and rebuilds the in-memory cache.
105 pub fn recover(&self) -> crate::Result<Vec<(u64, Vec<u8>)>> {
106 let wal = self.wal.lock().map_err(|_| crate::Error::Internal {
107 detail: "audit WAL lock poisoned".into(),
108 })?;
109
110 let records = wal.replay().map_err(crate::Error::Wal)?;
111
112 let mut entries = Vec::with_capacity(records.len());
113 for record in records {
114 if record.payload.len() < 8 {
115 tracing::warn!(
116 payload_len = record.payload.len(),
117 "skipping malformed audit WAL record (payload < 8 bytes)"
118 );
119 continue;
120 }
121 // Safe: length checked above guarantees exactly 8 bytes.
122 let data_lsn = u64::from_le_bytes(
123 record.payload[..8]
124 .try_into()
125 .expect("length checked above"),
126 );
127 let audit_bytes = record.payload[8..].to_vec();
128 entries.push((data_lsn, audit_bytes));
129 }
130
131 Ok(entries)
132 }
133}
134
135#[cfg(test)]

Callers 3

append_and_recoverFunction · 0.45
empty_recoveryFunction · 0.45
recover_audit_entriesMethod · 0.45

Calls 6

lockMethod · 0.80
replayMethod · 0.45
lenMethod · 0.45
expectMethod · 0.45
to_vecMethod · 0.45
pushMethod · 0.45

Tested by 2

append_and_recoverFunction · 0.36
empty_recoveryFunction · 0.36