rt store tests: the directory walk counts nothing for a file the removal takes while it lists it
tests::cache::a_store_filled_past_its_cap_stays_within_it_and_moves_on panicked on the XTX leg of
the matrix at e060958855 ("its metadata: NotFound"): bytes_under() walks the store's directory
while the store's removal thread deletes the dead generation, so an entry read_dir listed can be
gone by its metadata(). The walk now counts such an entry as nothing (NotFound only; any other
error still fails), which can only count less than the directory held when the walk started, so
the test's bound while a removal runs (at most 1.5 times the cap on disk) stays a sound check,
and its checks after settle() are unchanged.
Verified: the rt store tests and clippy of rt's targets in the check job named in the hand-over.
This commit is contained in:
1 parent
0bd215eee3
commit
f5927f1ff7
1 file changed
+10
-6
@@ -6,6 +6,7 @@
|
||||
|
||||
use crate::cache::{frame, unframe, State, Store};
|
||||
use std::fs;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
|
||||
use std::sync::Arc;
|
||||
@@ -33,18 +34,21 @@ impl Drop for Scratch {
|
||||
}
|
||||
}
|
||||
|
||||
/// The bytes of every file under `dir`; none where it is missing.
|
||||
/// The bytes of every file under `dir`; none where it is missing. A file or directory the store's
|
||||
/// removal thread takes while the walk lists it counts nothing: what the walk finds is never more
|
||||
/// than the directory held when it started.
|
||||
fn bytes_under(dir: &Path) -> u64 {
|
||||
let Ok(entries) = fs::read_dir(dir) else {
|
||||
return 0;
|
||||
};
|
||||
entries
|
||||
.map(|entry| {
|
||||
let entry = entry.expect("an entry");
|
||||
let meta = entry.metadata().expect("its metadata");
|
||||
match meta.is_dir() {
|
||||
true => bytes_under(&entry.path()),
|
||||
false => meta.len(),
|
||||
let meta = entry.and_then(|entry| Ok((entry.metadata()?, entry.path())));
|
||||
match meta {
|
||||
Ok((meta, path)) if meta.is_dir() => bytes_under(&path),
|
||||
Ok((meta, _)) => meta.len(),
|
||||
Err(error) if error.kind() == ErrorKind::NotFound => 0,
|
||||
Err(error) => panic!("{}: {error}", dir.display()),
|
||||
}
|
||||
})
|
||||
.sum()
|
||||
|
||||
Reference in new issue
Block a user