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,
)
| 308 | /// |
| 309 | /// Returns `(records, has_more)` where `has_more` is `true` if the limit was hit. |
| 310 | pub 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)] |
| 335 | mod tests { |
no test coverage detected