Footage cache (#3271): a decode thread lets go of its flight before handing the planes over

The decode thread's job held the flight until it ended, and the flight keeps the outcome for its waiters, so on a busy machine the planes just decoded still looked in use and the store dropped another file's instead (the eviction test failed on CI). The job now drops the flight before it sends the outcome. A test holds the decode thread after it sent; it fails with the old order. 300 runs of both eviction tests pass.
This commit is contained in:
vangel76 committed 2026-11-08 10:23:14 +01:00
1 parent 28e25246c4
commit 643c795bbf
2 files changed
+47 -3

No files matched your search

+13 -3
View File
@@ -371,12 +371,15 @@ pub(crate) fn decodes_of(path: &str) -> Vec<DecodeRecord> {
DECODES.lock().unwrap_or_else(PoisonError::into_inner).iter().filter(|(p, _)| p == path).map(|(_, d)| d.clone()).collect()
}
/// Run before a decode of a path is queued on the decode threads (`QUEUING`) and when the
/// queued job begins (`STARTING`), keyed by path (tests: holding a decode queued).
/// Run before a decode of a path is queued on the decode threads (`QUEUING`), when the
/// queued job begins (`STARTING`) and after it sent its outcome (`SENT`), keyed by path (tests:
/// holding a decode queued, or its decode thread busy after it).
#[cfg(test)]
pub(crate) static QUEUING: Mutex<Vec<(String, Hook)>> = Mutex::new(Vec::new());
#[cfg(test)]
pub(crate) static STARTING: Mutex<Vec<(String, Hook)>> = Mutex::new(Vec::new());
#[cfg(test)]
pub(crate) static SENT: Mutex<Vec<(String, Hook)>> = Mutex::new(Vec::new());
#[cfg(test)]
fn run_hook(hooks: &Mutex<Vec<(String, Hook)>>, path: &str) {
@@ -761,7 +764,14 @@ fn run(path: &str, source: &ExrSource, flight: &Arc<Flight>, base: Option<Arc<Ba
run_hook(&STARTING, &path);
// (claimed meanwhile by a decode thread: it decodes, and hands the outcome over)
if queued.take(RUNNING) {
let _ = tx.send(hints.run(|| decode(&path, &source, &queued, base, opened)));
let outcome = hints.run(|| decode(&path, &source, &queued, base, opened));
// (let go of the flight before the asker goes on: the flight keeps the outcome
// for its waiters, and a flight still held here would keep the planes looking in
// use, so the store would drop another file's instead)
drop(queued);
let _ = tx.send(outcome);
#[cfg(test)]
run_hook(&SENT, &path);
}
});
// A plain block: this thread runs nothing else meanwhile.
+34
View File
@@ -342,6 +342,40 @@ fn the_store_evicts_least_recently_used_by_bytes() {
assert!(!store.cached().contains(&path.to_string()));
}
/// #3271 CI: a decode thread that is slow to finish its job after handing the planes over (a
/// busy machine) doesn't make them look in use: the store still drops the least recently used
/// file, not another one.
#[test]
fn a_decode_thread_finishing_late_does_not_pin_the_planes() {
let bytes: Arc<[u8]> = write(vec![part(None, &RGBA, (32, 32), Compression::ZIP1)], (32, 32)).into();
let one = 4 * (32 * 32 * 4 + 1);
let store = PlaneStore::new(2 * one);
let all = Want { all: true, ids: Default::default() };
let get = |p: &str| {
let source = ExrSource::Bytes(bytes.clone());
let index = crate::exr_index::get(p, &source).unwrap();
store.get(p, &source, &index, &all, Use::Other).map(|_| ())
};
let (a, b, c) = ("/3271-late-a.exr", "/3271-late-b.exr", "/3271-late-c.exr");
// b's decode thread stays in its job (at most 10 s) after it sent the planes.
let (go, wait) = std::sync::mpsc::channel::<()>();
let wait = std::sync::Mutex::new(wait);
SENT.lock().unwrap().push((
b.to_string(),
Arc::new(move |_: &str| {
let _ = wait.lock().unwrap().recv_timeout(std::time::Duration::from_secs(10));
}),
));
get(a).unwrap();
get(b).unwrap();
get(a).unwrap();
get(c).unwrap();
let cached = store.cached();
let _ = go.send(());
SENT.lock().unwrap().retain(|(p, _)| p != b);
assert_eq!(cached, [a, c], "b was least recently used");
}
/// #474 / #3191: a file forgotten (Reload Footage) while it decodes keeps nothing of that decode,
/// and the request asks again: no planes made before the reload are kept or served.
#[test]