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

Function replay_from_limit_dir

nodedb-wal/src/segmented.rs:310–332  ·  view source on GitHub ↗

Paginated replay from a WAL directory: reads at most `max_records` from `from_lsn`. Uses sequential I/O (not mmap) and does NOT require the WAL mutex — safe to call concurrently with writes. Sealed segments are immutable; the active segment is read via buffered I/O which sees data after the writer's fsync. Returns `(records, has_more)` where `has_more` is `true` if the limit was hit.

(
    wal_dir: &Path,
    from_lsn: u64,
    max_records: usize,
)

Source from the content-addressed store, hash-verified

308///
309/// Returns `(records, has_more)` where `has_more` is `true` if the limit was hit.
310pub fn replay_from_limit_dir(
311 wal_dir: &Path,
312 from_lsn: u64,
313 max_records: usize,
314) -> Result<(Vec<WalRecord>, bool)> {
315 let segments = discover_segments(wal_dir)?;
316 let mut records = Vec::with_capacity(max_records.min(4096));
317
318 for seg in &segments {
319 let reader = crate::reader::WalReader::open(&seg.path)?;
320 for record_result in reader.records() {
321 let record = record_result?;
322 if record.header.lsn >= from_lsn {
323 records.push(record);
324 if records.len() >= max_records {
325 return Ok((records, true));
326 }
327 }
328 }
329 }
330
331 Ok((records, false))
332}
333
334#[cfg(test)]
335mod tests {

Callers 2

replay_from_limitMethod · 0.85
replay_from_limitMethod · 0.85

Calls 5

discover_segmentsFunction · 0.85
openFunction · 0.50
recordsMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected