Scan the WAL directory for segments that need archiving. Returns segments with LSN > last_archived_lsn, sorted by LSN.
(&self)
| 113 | /// |
| 114 | /// Returns segments with LSN > last_archived_lsn, sorted by LSN. |
| 115 | pub fn pending_segments(&self) -> std::io::Result<Vec<WalSegment>> { |
| 116 | let dir = &self.config.wal_dir; |
| 117 | if !dir.exists() { |
| 118 | return Ok(Vec::new()); |
| 119 | } |
| 120 | |
| 121 | let mut segments = Vec::new(); |
| 122 | for entry in std::fs::read_dir(dir)? { |
| 123 | let entry = entry?; |
| 124 | let path = entry.path(); |
| 125 | if !path.is_file() { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | // Parse segment filename: "wal-{first_lsn}-{last_lsn}.seg" |
| 130 | if let Some(seg) = parse_segment_filename(&path) |
| 131 | && seg.last_lsn > self.state.last_archived_lsn |
| 132 | { |
| 133 | segments.push(seg); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | segments.sort_by_key(|s| s.first_lsn); |
| 138 | if segments.len() > self.config.batch_size { |
| 139 | segments.truncate(self.config.batch_size); |
| 140 | } |
| 141 | |
| 142 | Ok(segments) |
| 143 | } |
| 144 | |
| 145 | /// Generate archive tasks for pending segments. |
| 146 | /// |