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

Method pending_segments

nodedb/src/wal/archiver.rs:115–143  ·  view source on GitHub ↗

Scan the WAL directory for segments that need archiving. Returns segments with LSN > last_archived_lsn, sorted by LSN.

(&self)

Source from the content-addressed store, hash-verified

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 ///

Callers 3

Calls 6

parse_segment_filenameFunction · 0.70
existsMethod · 0.45
pathMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
truncateMethod · 0.45

Tested by 3