From e27e90aa82b6c878e34b94a6fa238836f497b1c3 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 08:36:39 +0000 Subject: =?UTF-8?q?pipeline:=20dispatcher=20actor,=20worker=20pool=20and?= =?UTF-8?q?=20reaper=20(=C2=A78.2,=20=C2=A78.4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One dispatcher thread, N workers, one crossbeam channel between them. The dispatcher loop is reap -> cancel -> claim -> send, and the reaper runs first on every pass including the first, so 'recover from a crash' and 'notice an expired lease' are literally the same code path. There is no startup recovery routine to get wrong. - claim_batch does the SELECT and the UPDATE in one BEGIN IMMEDIATE transaction. SQLite has no SKIP LOCKED, but with exactly one writer the claim cannot race: nobody can see a row between the two statements. - Backpressure is min(max_concurrent_builds - in_flight, disk headroom), measured with statvfs. A build that cannot fit on disk stays queued instead of filling the filesystem halfway through a compile. - Retry policy (§8.4): transient failures (IO, HTTP) requeue up to max_transient_attempts; a deterministic build failure is never retried, and the release stays approved_but_unbuilt so the old version never looks healthy. Tests assert attempt==1 for build-fails and attempt==3 for a transient one. - A superseded candidate sets cancel_requested on in-flight builds; the worker stops at the step boundary rather than mid-step, which is what keeps the checkpoints honest. - Publish takes a process-wide lock so two workers cannot interleave the index rewrite. The critical section is the db file rewrite, never a build. - The deterministic build id makes re-enqueue an INSERT OR IGNORE no-op, so a careless 'rebuild that again' is harmless. tests/dispatch.rs drives the real threads: the pool takes a queued build all the way to publication, a reaped build resumes from its checkpoints without re-running makechrootpkg, and backpressure admits exactly one build per slot. Serve now starts the pool alongside the watcher and the HTTP server. --- src/pipeline/publish.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/pipeline/publish.rs') diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 5d03a06..d54314e 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -58,7 +58,20 @@ fn index_artifacts(db: &Db, extra: &[PathBuf]) -> Result> { } /// Publish the collected artifacts of a build. Returns the new release id. +/// One publish at a time per repo (§8.2, §9). With `max_concurrent_builds > 1` +/// two workers could otherwise interleave the index rewrite; the critical +/// section is the db file rewrite only, never a build. +static PUBLISH_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + pub fn publish(ctx: &Ctx) -> Result { + let _guard = match PUBLISH_LOCK.lock() { + Ok(g) => g, + // A previous publish panicked while holding it. The index on disk is + // still whatever was last renamed into place — atomic publish means a + // poisoned lock cannot have left a half-written db — so we clear the + // poison and continue rather than wedge the queue forever. + Err(p) => p.into_inner(), + }; let collect = Collect::load(&ctx.collect_path)?; if collect.packages.is_empty() { return Err(Error::invalid("nothing to publish")); -- cgit v1.2.3