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

Function parse_segment_filename

nodedb/src/wal/archiver.rs:233–250  ·  view source on GitHub ↗

Parse a WAL segment filename into a WalSegment. Expected format: `wal-{first_lsn_hex}-{last_lsn_hex}.seg`

(path: &Path)

Source from the content-addressed store, hash-verified

231///
232/// Expected format: `wal-{first_lsn_hex}-{last_lsn_hex}.seg`
233fn parse_segment_filename(path: &Path) -> Option<WalSegment> {
234 let stem = path.file_stem()?.to_str()?;
235 let parts: Vec<&str> = stem.split('-').collect();
236 if parts.len() != 3 || parts[0] != "wal" {
237 return None;
238 }
239
240 let first_lsn = u64::from_str_radix(parts[1], 16).ok()?;
241 let last_lsn = u64::from_str_radix(parts[2], 16).ok()?;
242 let size_bytes = std::fs::metadata(path).ok()?.len();
243
244 Some(WalSegment {
245 path: path.to_path_buf(),
246 first_lsn: Lsn::new(first_lsn),
247 last_lsn: Lsn::new(last_lsn),
248 size_bytes,
249 })
250}
251
252#[cfg(test)]
253mod tests {

Callers 2

pending_segmentsMethod · 0.70

Calls 4

metadataFunction · 0.85
collectMethod · 0.80
lenMethod · 0.45
okMethod · 0.45

Tested by 1