in below/store/src/lib.rs [606:664]
fn discard_until<F>(&self, f: F) -> Result<bool>
where
F: Fn(u64) -> bool,
{
let entries = get_index_files(self.dir.as_path())?;
// Entries are sorted with increasing timestamp
for entry in entries {
let v: Vec<&str> = entry.split('_').collect();
if v.len() != 2 {
warn!(self.logger, "Invalid index file name: {}", entry);
continue;
}
let entry_shard = match v[1].parse::<u64>() {
Ok(val) => val,
_ => {
warn!(self.logger, "Cannot parse index shard: {}", entry);
continue;
}
};
if f(entry_shard) {
return Ok(true);
}
if entry_shard >= self.shard {
return Ok(false);
}
// Removal order doesn't matter at all, it's the
// responsibility of the read side to handle missing files
let mut index_path = self.dir.clone();
index_path.push(&entry);
match std::fs::remove_file(&index_path) {
Err(e) if e.kind() != ErrorKind::NotFound => {
return Err(e).context(format!(
"Failed to remove index file: {}",
index_path.display()
));
}
_ => {}
};
let mut data_path = self.dir.clone();
data_path.push(format!("data_{:011}", entry_shard));
match std::fs::remove_file(&data_path) {
Err(e) if e.kind() != ErrorKind::NotFound => {
return Err(e).context(format!(
"Failed to remove data file: {}",
data_path.display()
));
}
_ => {}
};
}
Ok(false)
}