diff options
Diffstat (limited to 'src/db/builds.rs')
| -rw-r--r-- | src/db/builds.rs | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/src/db/builds.rs b/src/db/builds.rs index 072836b..8598dd3 100644 --- a/src/db/builds.rs +++ b/src/db/builds.rs @@ -1,5 +1,3 @@ -//! Build queue rows: deterministic ids, leases, step checkpoints (§8.1, §8.2). - use rusqlite::{params, Connection, OptionalExtension}; use crate::db::{BuildState, Db, StepState}; @@ -160,12 +158,10 @@ pub fn extend_lease(db: &Db, id: &str, lease_secs: i64) -> Result<()> { }) } -/// Reaper pass (§8.2): expired leases go back to the queue and their in-flight -/// step is marked interrupted, so the checkpoint decides where it resumes. +/// Reaper pass (§8.2): expired leases go back to the queue and their in-flight step +/// is marked interrupted, so the checkpoint decides where it resumes. /// -/// Both `leased` and `running` are reaped: a worker sets `running` as soon as it -/// starts a step, so a process that dies mid-step leaves a `running` row, not a -/// `leased` one. Reaping only `leased` would strand every real crash. +/// Both `leased` and `running` are reaped: a mid-step death leaves a `running` row. pub fn reap_expired(db: &Db) -> Result<usize> { let now = time::now(); db.writer.tx(move |tx| { @@ -195,10 +191,8 @@ pub fn reap_expired(db: &Db) -> Result<usize> { /// The one way a build changes state, usable inside a transaction. /// -/// The write is a compare-and-swap: only a row currently in one of `to`'s legal -/// predecessor states is updated, so two workers cannot both land a terminal -/// state, and a zombie worker whose lease was reaped gets an error instead of -/// silently rewriting a build that has since been handed to somebody else. +/// The write is a compare-and-swap: only a row in one of `to`'s legal predecessor +/// states is updated, so a zombie worker whose lease was reaped gets an error. fn transition_in_tx( tx: &mut rusqlite::Transaction<'_>, id: &str, @@ -248,13 +242,10 @@ pub fn block_on(db: &Db, id: &str, blocked_on: &[String]) -> Result<()> { }) } -/// Re-check blocked builds whenever a publish lands (§10.4). /// Requeue blocked builds whose blocking packages have since arrived (§10.4). /// -/// Not "requeue everything that is blocked": the dispatcher calls this every -/// pass, and requeueing a build that will immediately block again is a busy loop -/// that burns a claim and a plan step each tick. A build only goes back on the -/// queue when every name it is waiting for is actually in the index now. +/// Not "requeue everything that is blocked": the dispatcher calls this every pass, +/// and requeueing a build that will immediately block again burns a claim each tick. pub fn requeue_blocked(db: &Db) -> Result<usize> { let now = time::now(); db.writer.tx(move |tx| { @@ -265,9 +256,8 @@ pub fn requeue_blocked(db: &Db) -> Result<usize> { .collect::<rusqlite::Result<Vec<(String, String)>>>()?; out }; - // The index membership check is one query for the whole pass, not one - // per dependency of every blocked build (m-17): the old shape was an N+1 - // whose N grew with the backlog, and it ran on the dispatcher's hot loop. + // The index membership check is one query for the whole pass, not one per + // dependency of every blocked build (m-17), on the dispatcher's hot loop. let in_index: std::collections::HashSet<String> = { let mut stmt = tx.prepare("SELECT name FROM package WHERE state='in_index'")?; let names = stmt @@ -544,8 +534,7 @@ pub fn current_state(c: &Connection, id: &str) -> Result<Option<BuildState>> { /// Claim up to `limit` queued builds in one `BEGIN IMMEDIATE` transaction and /// hand them to workers (§8.2). SQLite has no `SKIP LOCKED`, but with exactly one -/// writer the claim cannot race: the SELECT and the UPDATE are the same -/// transaction, so no other claimer can see a row in between. +/// writer the claim cannot race: the SELECT and the UPDATE are one transaction. pub fn claim_batch(db: &Db, owner: &str, limit: usize, lease_secs: i64) -> Result<Vec<String>> { if limit == 0 { return Ok(Vec::new()); @@ -597,9 +586,9 @@ pub fn requeue_transient(db: &Db, id: &str) -> Result<()> { .tx(move |tx| transition_in_tx(tx, &id, BuildState::Queued, None)) } -/// Explicitly retry a failed build (§8.4). This is a human decision, not a -/// policy: the failed step is put back to pending so it runs again, everything -/// that succeeded stays checkpointed, and the attempt counter keeps counting. +/// Explicitly retry a failed build (§8.4): the failed step goes back to pending, +/// everything that succeeded stays checkpointed, and the attempt counter keeps +/// counting. pub fn retry(db: &Db, id: &str) -> Result<()> { let id = id.to_string(); db.writer.tx(move |tx| { @@ -609,8 +598,7 @@ pub fn retry(db: &Db, id: &str) -> Result<()> { params![id], )?; // The move itself goes through the machine, so requeueing a build that - // already published is refused with a reason instead of silently - // re-queueing a row whose every step is checkpointed as done. + // already published is refused with a reason. transition_in_tx(tx, &id, BuildState::Queued, None)?; tx.execute("UPDATE build SET cancel_requested=0 WHERE id=?1", params![id])?; Ok(()) |
