diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ecfc7d6..81c0d54a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,17 @@ and listed with their assets on the ## [Unreleased] +### Changed + +- **A stack starts sooner** (measured in the pool's telemetry: a lane on a + node took about 154 s, of which 51 s waiting for its containers before + any build, and 37 s building what an earlier lane had built). The + services are built while the containers start, Compose groups that no + `after` orders start side by side (here and on a node), and services + whose `after` is done start side by side. A node keeps the member's + build artifacts with its store (ADR-0062 addendum): the member's next + lane with the same inputs copies them instead of building. + ### Added - **A pool grows by machines a provisioner makes** (ADR-0051): with diff --git a/crates/devstack-daemon/src/supervisor/artifacts.rs b/crates/devstack-daemon/src/supervisor/artifacts.rs index 77bd344d..e3f5c519 100644 --- a/crates/devstack-daemon/src/supervisor/artifacts.rs +++ b/crates/devstack-daemon/src/supervisor/artifacts.rs @@ -141,6 +141,7 @@ impl Supervisor { } let base = build_id(&snap.manifest, svc).map_err(|e| e.to_string())?; let mut id = base.clone(); + let mut from_store = false; // `--rebuild`: the same inputs once more, under `-`; the artifact // that exists may be running and is never overwritten (ADR-0002). if forced { @@ -163,9 +164,27 @@ impl Supervisor { "why": "an artifact for these inputs exists (watch paths, build files above them, build command); `devstack restart --rebuild` builds anyway", }), ); + } else if let Some(ms) = self.copy_from_node_store(name, &id) { + from_store = true; + crate::diag::info( + "build_reused", + serde_json::json!({ + "lane": self.lane, + "service": name, + "build_id": id, + "source": "store", + "ms": ms, + "why": "a lane of this member built these inputs on this node before (its artifact store); `devstack restart --rebuild` builds anyway", + }), + ); } - if self.builder.artifact(name, &id).is_none() { - building(Some(id.clone())); + let missing = self.builder.artifact(name, &id).is_none(); + // An artifact from the node's store came without its `prepare`: the + // lane's worktree gets what `prepare` makes as a build's would. + if missing || from_store { + if missing { + building(Some(id.clone())); + } if let Some(job) = self.prepare_job(name, svc, &snap)? { drop(snap); let view = self.run_prepare(name, job, cancel)?; @@ -173,6 +192,8 @@ impl Supervisor { snap = self.snapshot.lock().unwrap(); } self.link_prepared(name, svc); + } + if missing { let t0 = Instant::now(); let mut running = self .builder @@ -216,7 +237,10 @@ impl Supervisor { }; self.build_done(name, &id, t0, result); match outcome { - Outcome::Published { .. } => self.prune_artifacts(name), + Outcome::Published { .. } => { + self.put_in_node_store(name, &id, t0.elapsed()); + self.prune_artifacts(name) + } Outcome::Stale { .. } => { crate::diag::warn( "build_discarded", @@ -245,6 +269,78 @@ impl Supervisor { Ok(Some((id.clone(), self.layout.artifact(name, &id)))) } + /// In a lane on a node: the member's artifact store there (card on the + /// pull request of 2026-10-28): `artifacts` in the member's store the + /// node mounts read-only, new entries through the lane's outbox, which + /// the agent takes in. Keyed by the build id and the lane image, whose + /// toolchain built it. `None` elsewhere, or from an agent that gives no + /// store or no image. + fn node_artifacts(&self) -> Option<(devstack_build::store::Store, String)> { + let (root, outbox) = super::copy::node_store()?; + let image = std::env::var("DEVSTACK_LANE_IMAGE") + .ok() + .filter(|i| !i.is_empty())?; + let image = blake3::hash(image.as_bytes()).to_hex()[..12].to_string(); + Some(( + devstack_build::store::Store::with_outbox( + root.join("artifacts"), + outbox.join("artifacts"), + ), + image, + )) + } + + /// The artifact of `id` from the node's store, into this lane's own: + /// how long the copy took, `None` when the store has none. + fn copy_from_node_store(&self, name: &str, id: &str) -> Option { + let (store, image) = self.node_artifacts()?; + let key = format!("{id}-{image}"); + store.get(name, &key)?; + let t0 = Instant::now(); + let dir = self.layout.artifacts(name); + // Copied beside it, then moved: an artifact is there whole or not. + let tmp = dir.join(format!(".store-{}-{id}", std::process::id())); + let _ = std::fs::remove_dir_all(&tmp); + let copied = std::fs::create_dir_all(&tmp) + .and_then(|()| store.copy_into(name, &key, &tmp).map(|_| ())) + .and_then(|()| std::fs::rename(tmp.join(id), dir.join(id))); + let _ = std::fs::remove_dir_all(&tmp); + match copied { + Ok(()) if self.builder.artifact(name, id).is_some() => { + Some(t0.elapsed().as_millis() as u64) + } + Ok(()) => None, + Err(e) => { + crate::diag::warn( + "build_store_copy_failed", + serde_json::json!({ "lane": self.lane, "service": name, "build_id": id, "error": e.to_string() }), + ); + None + } + } + } + + /// A build of `id` published: into the node's store for the member's + /// next lane with the same inputs. + fn put_in_node_store(&self, name: &str, id: &str, took: Duration) { + let Some((store, image)) = self.node_artifacts() else { + return; + }; + let key = format!("{id}-{image}"); + if let Err(e) = store.put( + name, + &key, + &self.layout.artifacts(name), + &[id.to_string()], + took, + ) { + crate::diag::warn( + "build_store_put_failed", + serde_json::json!({ "lane": self.lane, "service": name, "build_id": id, "error": e.to_string() }), + ); + } + } + /// A build ended: how long it ran and how (ADR-0037 point 4). fn build_done(&self, name: &str, id: &str, t0: Instant, result: &str) { crate::diag::info( diff --git a/crates/devstack-daemon/src/supervisor/copy.rs b/crates/devstack-daemon/src/supervisor/copy.rs index 0b47780a..e78198fa 100644 --- a/crates/devstack-daemon/src/supervisor/copy.rs +++ b/crates/devstack-daemon/src/supervisor/copy.rs @@ -1034,7 +1034,7 @@ fn store_key_of(key: &str, outputs: &[String], version: Option<&str>) -> String /// In a lane on a node: the member's store the node mounts read-only /// (`DEVSTACK_STORE`), and the outbox in the lane's slot its agent takes new /// entries from (`DEVSTACK_STORE_OUT`), ADR-0062 points 3, 4. -fn node_store() -> Option<(PathBuf, PathBuf)> { +pub(super) fn node_store() -> Option<(PathBuf, PathBuf)> { if !crate::remote_lane() { return None; } diff --git a/crates/devstack-daemon/src/supervisor/infra.rs b/crates/devstack-daemon/src/supervisor/infra.rs index 9eba644f..9bebab4a 100644 --- a/crates/devstack-daemon/src/supervisor/infra.rs +++ b/crates/devstack-daemon/src/supervisor/infra.rs @@ -393,7 +393,40 @@ impl Supervisor { // The node's agent starts it, after this daemon (ADR-0025, #164). return self.node_infra_up(&file); } - for g in self.group_order() { + // Groups no `after` orders start side by side. + let deps: BTreeMap> = self + .stack + .compose + .iter() + .map(|(k, g)| (k.clone(), g.after.clone())) + .collect(); + for level in super::levels(&deps) { + let results: Vec> = std::thread::scope(|s| { + let running: Vec<_> = level + .iter() + .map(|g| s.spawn(move || self.group_up(g))) + .collect(); + running + .into_iter() + .map(|h| { + h.join().unwrap_or_else(|_| { + Err("a compose group's start failed inside devstack".into()) + }) + }) + .collect() + }); + if let Some(e) = results.into_iter().find_map(Result::err) { + return Err(e); + } + } + self.refresh_infra(); + Ok(()) + } + + /// Start compose group `g` and wait until it is ready. + fn group_up(&self, g: &str) -> Result<(), String> { + let g = g.to_string(); + { self.emit(EventBody::Infra { group: g.clone(), message: "starting".into(), @@ -450,7 +483,7 @@ impl Supervisor { if self.lane.is_empty() { self.hold_ports(&g, &held); } - continue; + return Ok(()); } if let Err(e) = self.docker.up(&group, Duration::from_secs(300)) { let msg = e.to_string(); @@ -470,7 +503,6 @@ impl Supervisor { message: "ready".into(), }); } - self.refresh_infra(); Ok(()) } diff --git a/crates/devstack-daemon/src/supervisor/lifecycle.rs b/crates/devstack-daemon/src/supervisor/lifecycle.rs index 516cbbe0..cd7c9d02 100644 --- a/crates/devstack-daemon/src/supervisor/lifecycle.rs +++ b/crates/devstack-daemon/src/supervisor/lifecycle.rs @@ -126,8 +126,19 @@ impl Supervisor { // volumes go first, once per start, so its seed jobs fill new // ones. On a node its agent does it (ADR-0025). self.fresh_data(); - // Every lane has its own infrastructure (ADR-0030). - self.infra_up()?; + // Every lane has its own infrastructure (ADR-0030). A build needs + // no container: the services are built while it starts. + let infra = { + let me = self.clone(); + std::thread::Builder::new() + .name("infra-up".into()) + .spawn(move || me.infra_up()) + .map_err(|e| e.to_string())? + }; + self.prebuild(); + infra + .join() + .map_err(|_| "starting the infrastructure failed inside devstack".to_string())??; // Healthy inside Docker is not reachable from here: say so // (a service that needs the container repairs it, ensure_after). for (g, svc, lost) in self.check_forwards(true) { @@ -142,26 +153,42 @@ impl Supervisor { } // A failed service holds back only what comes `after` it; everything // independent of it still starts (one broken build must not keep the - // rest of the stack down). + // rest of the stack down). Services whose `after` is done start at + // once, side by side. let mut failed: BTreeSet = BTreeSet::new(); - for name in self.service_order() { - let svc = self.service(&name)?; - if !svc.autostart || !self.runs_here(svc) { - continue; - } - if let Some(dep) = svc.after.iter().find(|d| failed.contains(*d)) { - self.set_status( - &name, - Status::Failed { - reason: format!("not started: `{dep}` failed"), - }, - ); - failed.insert(name); - continue; - } - if self.start(&name).is_err() { - failed.insert(name); + for level in super::levels(&self.service_deps()) { + let mut go = Vec::new(); + for name in level { + let svc = self.service(&name)?; + if !svc.autostart || !self.runs_here(svc) { + continue; + } + if let Some(dep) = svc.after.iter().find(|d| failed.contains(*d)) { + self.set_status( + &name, + Status::Failed { + reason: format!("not started: `{dep}` failed"), + }, + ); + failed.insert(name); + continue; + } + go.push(name); } + let results: Vec<(String, bool)> = std::thread::scope(|s| { + let running: Vec<_> = go + .into_iter() + .map(|name| { + let me = self.clone(); + s.spawn(move || { + let ok = me.start(&name).is_ok(); + (name, ok) + }) + }) + .collect(); + running.into_iter().filter_map(|h| h.join().ok()).collect() + }); + failed.extend(results.into_iter().filter(|(_, ok)| !ok).map(|(n, _)| n)); } if failed.is_empty() { Ok(()) @@ -173,6 +200,45 @@ impl Supervisor { } } + /// Build what the start will run, while the infrastructure starts: each + /// service with `build` that starts with the tree and has no artifact + /// to restore (ADR-0016). Its start then finds the artifact. One that + /// fails here (a build that needs a container after all) is built again + /// by its start, which says why. + fn prebuild(self: &Arc) { + let first: Vec = self.started.lock().unwrap().iter().cloned().collect(); + for name in self.service_order() { + let Ok(declared) = self.service(&name) else { + continue; + }; + if !declared.autostart || !self.runs_here(declared) || first.contains(&name) { + continue; + } + let svc = self.effective(&name, declared); + if svc.build.is_none() + || !super::on_this_platform(&svc) + || self.restorable(&name).is_some() + { + continue; + } + let epoch = self.stop_epoch(&name); + let _op = self.op_locks[&name].lock().unwrap(); + if self.slots.lock().unwrap()[&name].view.status.is_active() { + continue; + } + let cancel = || self.stopped_since(&name, epoch); + let t0 = std::time::Instant::now(); + let r = self.build_locked(&name, &svc, &cancel, epoch); + crate::diag::info( + "prebuilt", + serde_json::json!({ "lane": self.lane, "service": name, + "ms": t0.elapsed().as_millis() as u64, "error": r.as_ref().err() }), + ); + // Built, not started: it waits for the infrastructure. + self.set_status(&name, Status::Stopped); + } + } + fn fresh_data(&self) { let fresh = self .stack @@ -543,7 +609,7 @@ impl Supervisor { return Ok(p.clone()); } let port = svc.port.expect("proxied services have a port"); - if port_in_use(port) { + if !port_freed(port) { return Err(super::port_taken(port)); } let p = @@ -674,7 +740,7 @@ impl Supervisor { None } else { if let Some(port) = svc.port - && port_in_use(port) + && !port_freed(port) { return Err(super::port_taken(port)); } @@ -1344,3 +1410,17 @@ impl Supervisor { Ok(()) } } + +/// Whether `port` is free, or becomes free within a while: held a moment +/// longer by something on its way out (the instance of a daemon that just +/// restarted, ADR-0052), as for a front. +fn port_freed(port: u16) -> bool { + let t0 = std::time::Instant::now(); + while port_in_use(port) { + if t0.elapsed() >= Duration::from_secs(10) { + return false; + } + std::thread::sleep(Duration::from_millis(250)); + } + true +} diff --git a/crates/devstack-daemon/src/supervisor/mod.rs b/crates/devstack-daemon/src/supervisor/mod.rs index dd7def58..d1bf15ce 100644 --- a/crates/devstack-daemon/src/supervisor/mod.rs +++ b/crates/devstack-daemon/src/supervisor/mod.rs @@ -960,6 +960,25 @@ impl Supervisor { ) } + /// Each service's services it comes `after` (Compose dependencies are + /// `infra_up`'s). + pub(super) fn service_deps(&self) -> BTreeMap> { + self.stack + .services + .iter() + .map(|(k, s)| { + ( + k.clone(), + s.after + .iter() + .filter(|a| !a.starts_with("compose.")) + .cloned() + .collect(), + ) + }) + .collect() + } + /// `svc` runs in this supervisor: on this platform, and in a lane only /// unless it says `lanes = false`. fn runs_here(&self, svc: &Service) -> bool { @@ -1182,6 +1201,32 @@ fn topo(deps: BTreeMap>) -> Vec { out } +/// The names of `deps` in levels: each one's dependencies (those among +/// `deps`) in an earlier level, so the members of a level can go at once. +/// A cycle (the stack file check refuses one) ends up in the last level. +fn levels(deps: &BTreeMap>) -> Vec> { + let mut level: BTreeMap = BTreeMap::new(); + for n in topo(deps.clone()) { + let l = deps + .get(&n) + .into_iter() + .flatten() + .filter_map(|d| level.get(d)) + .map(|l| l + 1) + .max() + .unwrap_or(0); + level.insert(n, l); + } + let mut out: Vec> = Vec::new(); + for (n, l) in level { + if out.len() <= l { + out.resize(l + 1, Vec::new()); + } + out[l].push(n); + } + out +} + /// Taken on IPv4 or IPv6 loopback. A dev server bound to `localhost` may hold /// only `::1` (Node on Windows); binding `127.0.0.1` would still succeed. A host /// without IPv6 fails the `::1` bind with another error, which is not "in use". @@ -1311,6 +1356,36 @@ fn lsof_holder(text: &str) -> Option { } } +#[cfg(test)] +mod level_tests { + #[test] + fn what_no_after_orders_shares_a_level() { + let deps = |pairs: &[(&str, &[&str])]| { + pairs + .iter() + .map(|(n, d)| (n.to_string(), d.iter().map(|x| x.to_string()).collect())) + .collect() + }; + // mocks side by side; the migrator first, then the api, then the spa. + let l = super::levels(&deps(&[ + ("ai-mock", &[]), + ("cituro-mock", &[]), + ("migrate", &[]), + ("api", &["migrate", "ai-mock"]), + ("spa", &["api"]), + ("outside", &["not-a-service"]), + ])); + assert_eq!( + l, + vec![ + vec!["ai-mock", "cituro-mock", "migrate", "outside"], + vec!["api"], + vec!["spa"] + ] + ); + } +} + #[cfg(test)] mod holder_tests { use super::*; diff --git a/crates/devstack-node/src/lanerun.rs b/crates/devstack-node/src/lanerun.rs index 85d64d54..3245dde0 100644 --- a/crates/devstack-node/src/lanerun.rs +++ b/crates/devstack-node/src/lanerun.rs @@ -119,9 +119,12 @@ pub struct Started { /// What a start leaves for after the lane's daemon answered (#164): its /// Compose groups' containers, created and checked, started and waited for -/// in order, as a local lane's daemon does. The daemon waits for them. +/// in `after` order (groups no `after` orders side by side), as a local +/// lane's daemon does. The daemon waits for them. pub struct InfraUp { groups: Vec<(String, Group)>, + /// Each group's groups it comes after. + after: std::collections::BTreeMap>, } /// How long a group's containers may take to be healthy once started. @@ -142,20 +145,20 @@ impl InfraUp { pub fn run( &self, lane: &LaneRun, - stop: &dyn Fn() -> bool, - done: &dyn Fn(&str, Duration, Option<&str>), + stop: &(dyn Fn() -> bool + Sync), + done: &(dyn Fn(&str, Duration, Option<&str>) + Sync), ) -> std::result::Result<(), String> { let dc = Docker::clean(); let src = lane.src(); + // The state file is written by one group at a time. + let writing = std::sync::Mutex::new(()); let set = |group: &str, state: &str, error: Option<&str>| { + let _one = writing.lock().unwrap(); if let Err(e) = crate::laneinfra::set_group(&lane.dir, &src, group, state, error) { eprintln!("lane {}: compose group `{group}`: {e}", lane.id); } }; - for (i, (name, g)) in self.groups.iter().enumerate() { - if stop() { - return Ok(()); - } + let up = |name: &str, g: &Group| -> std::result::Result<(), String> { let t = std::time::Instant::now(); set(name, crate::laneinfra::STARTING, None); // Nothing is built here: the lane runs by now, and its build @@ -168,18 +171,61 @@ impl InfraUp { Ok(()) => { set(name, crate::laneinfra::UP, None); done(name, t.elapsed(), None); + Ok(()) } Err(e) => { let e = e.to_string(); set(name, crate::laneinfra::FAILED, Some(&e)); done(name, t.elapsed(), Some(&e)); - let why = format!("not started: compose group `{name}` failed"); - for (rest, _) in &self.groups[i + 1..] { - set(rest, crate::laneinfra::FAILED, Some(&why)); - } - return Err(format!("compose group `{name}`: {e}")); + Err(format!("compose group `{name}`: {e}")) } } + }; + let mut left: Vec<&(String, Group)> = self.groups.iter().collect(); + let mut finished: BTreeSet = BTreeSet::new(); + while !left.is_empty() { + if stop() { + return Ok(()); + } + // Those whose groups `after` are up start now, side by side. + let (now, later): (Vec<_>, Vec<_>) = left.into_iter().partition(|(n, _)| { + self.after + .get(n) + .into_iter() + .flatten() + .all(|d| finished.contains(d) || !self.groups.iter().any(|(o, _)| o == d)) + }); + // A cycle (the stack file check refuses one): one at a time. + let (now, later) = if now.is_empty() { + let mut l = later; + let first = l.remove(0); + (vec![first], l) + } else { + (now, later) + }; + let results: Vec> = std::thread::scope(|s| { + let running: Vec<_> = now.iter().map(|(n, g)| s.spawn(|| up(n, g))).collect(); + running + .into_iter() + .map(|h| { + h.join() + .unwrap_or_else(|_| Err("a group's start failed".into())) + }) + .collect() + }); + if let Some((i, e)) = results + .iter() + .enumerate() + .find_map(|(i, r)| r.as_ref().err().map(|e| (i, e))) + { + let why = format!("not started: compose group `{}` failed", now[i].0); + for (rest, _) in &later { + set(rest, crate::laneinfra::FAILED, Some(&why)); + } + return Err(e.clone()); + } + finished.extend(now.iter().map(|(n, _)| n.clone())); + left = later; } Ok(()) } @@ -1003,6 +1049,10 @@ impl LaneRun { infra_udp_ports, }, infra: InfraUp { + after: groups + .iter() + .map(|(n, _, _)| (n.clone(), stack.compose[n].after.clone())) + .collect(), groups: groups.into_iter().map(|(n, g, _)| (n, g)).collect(), }, }) diff --git a/crates/devstack-node/src/node.rs b/crates/devstack-node/src/node.rs index 451e8be5..9fbebe1c 100644 --- a/crates/devstack-node/src/node.rs +++ b/crates/devstack-node/src/node.rs @@ -672,7 +672,16 @@ impl Inner { // entries no lane used for as long as a stopped lane is kept go; // the rest counts with the member's kept lanes. let mut stored: HashMap> = HashMap::new(); - for (dir, member) in self.prepare_stores() { + let with_artifacts: Vec<(PathBuf, String)> = self + .prepare_stores() + .into_iter() + .flat_map(|(dir, member)| { + // The artifacts of the member's builds go the same way. + let arts = dir.join("artifacts"); + [(dir, member.clone()), (arts, member)] + }) + .collect(); + for (dir, member) in with_artifacts { let store = devstack_build::store::Store::new(&dir); for s in store.sweep(keep_for, false) { eprintln!( @@ -1189,6 +1198,15 @@ impl Inner { for (service, key) in devstack_build::store::Store::new(dir).take_in(&outbox) { eprintln!("store of `{}`: took in {service}/{key}", run.lane); } + // The artifacts its builds published, for the member's next lane. + for (service, key) in devstack_build::store::Store::new(dir.join("artifacts")) + .take_in(&outbox.join("artifacts")) + { + eprintln!( + "store of `{}`: took in the artifact {service}/{key}", + run.lane + ); + } } } diff --git a/crates/devstack-node/tests/provision.rs b/crates/devstack-node/tests/provision.rs index 9111d522..cea1e418 100644 --- a/crates/devstack-node/tests/provision.rs +++ b/crates/devstack-node/tests/provision.rs @@ -325,6 +325,9 @@ fn an_enrolment_from_another_address_is_refused_and_an_alarm() { .unwrap(); let e = offer_of(&dev, dev.lease_or_wait(&ask("a")).unwrap()).unwrap_err(); assert!(e.contains("given back"), "{e}"); + // The mock records the machine once its refused enrolment returned, + // which may be after the lease was given back. + until("enrolled", 10, || !enrolled.lock().unwrap().is_empty()); assert_eq!(enrolled.lock().unwrap().len(), 1); let l = Local::new(&enrolled.lock().unwrap()[0]); assert!(l.nodes().is_err(), "it never joined"); diff --git a/crates/devstack/tests/remote_lane.rs b/crates/devstack/tests/remote_lane.rs index 24e3dd74..acb96d18 100644 --- a/crates/devstack/tests/remote_lane.rs +++ b/crates/devstack/tests/remote_lane.rs @@ -300,7 +300,7 @@ fn a_lane_runs_on_a_node_of_the_pool() { "the lane's daemon answered only once its db was healthy" ); // Its services start only once its infrastructure is up, as a local - // lane's: `api` leaves `stopped` with the db healthy. + // lane's: `api` may build meanwhile, but starts with the db healthy. let until = Instant::now() + Duration::from_secs(600); loop { let api_state = api("/v1/lanes/wt/v1/stack").and_then(|v| { @@ -310,7 +310,7 @@ fn a_lane_runs_on_a_node_of_the_pool() { .find(|s| s["name"] == "api") .and_then(|s| s["status"]["state"].as_str().map(str::to_string)) }); - if let Some(st) = api_state.filter(|s| s != "stopped") { + if let Some(st) = api_state.filter(|s| s != "stopped" && s != "building") { assert_eq!( lane_db("{{.State.Health.Status}}"), "healthy", @@ -691,15 +691,31 @@ fn a_lane_runs_on_a_node_of_the_pool() { assert!(info.contains("\"workers\":true"), "{info}"); let list = cli(&main, &["lane", "list"]); assert!(list.contains("wt: runs its background workers"), "{list}"); - let (st, body) = api_request( - &main, - state.path(), - "POST", - "/v1/lanes/wt/v1/telemetry/take", - ) - .expect("the lane answers"); - assert_eq!(st, 200, "{body}"); - assert!(body.contains("prepare_store_hit"), "{body}"); + // Its build too: the member's artifact store on the node has the + // artifact the lane's first start built (the card of 2026-10-28). The + // services start side by side, so the lines are gathered until both + // came (a take hands each line once). + let mut body = String::new(); + let until = Instant::now() + Duration::from_secs(120); + loop { + let (st, b) = api_request( + &main, + state.path(), + "POST", + "/v1/lanes/wt/v1/telemetry/take", + ) + .expect("the lane answers"); + assert_eq!(st, 200, "{b}"); + body.push_str(&b); + if body.contains("prepare_store_hit") + && body.contains("build_reused") + && body.contains("\"source\":\"store\"") + { + break; + } + assert!(Instant::now() < until, "{body}"); + std::thread::sleep(Duration::from_millis(500)); + } // `down --all`: the daemon ends, and the lane on the node goes with it // (ADR-0025 point 7). @@ -903,6 +919,9 @@ fn store_entries(dir: &Path) -> usize { let path = e.path(); if in_stores && path.join(".devstack-store.json").is_file() { 1 + } else if in_stores && e.file_name() == "artifacts" { + // The build artifacts' store, not `prepare`'s. + 0 } else if path.is_dir() && !path.is_symlink() { count(&path, in_stores || e.file_name() == "stores") } else { diff --git a/docs/adr/0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md b/docs/adr/0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md index 842c6f1e..5b3eea4b 100644 --- a/docs/adr/0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md +++ b/docs/adr/0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md @@ -1,6 +1,6 @@ # ADR-0062: What `prepare` makes is kept in a store per machine and repository, keyed by its inputs -- **Status:** Accepted (2026-10-26); measured and built on the developer's machine, noted 2026-10-26; built on nodes, noted 2026-10-26 +- **Status:** Accepted (2026-10-26); measured and built on the developer's machine, noted 2026-10-26; built on nodes, noted 2026-10-26; addendum 2026-10-28 (a node keeps the member's build artifacts too; card on the pull request) - **Date:** 2026-10-26 - **Deciders:** project owner - **Related:** [#277](https://github.com/nuetzliches/devstack/issues/277), [ADR-0002](0002-processes-run-from-immutable-artifacts.md), [ADR-0024](0024-a-lane-is-a-supervisor-in-the-main-trees-daemon.md) (a lane runs from a copy), [ADR-0028](0028-lane-images.md) (point 3), [ADR-0033](0033-a-node-decides-what-runs-on-it.md), [ADR-0034](0034-a-machine-can-belong-to-several-pools.md), [ADR-0038](0038-a-lanes-data-outlives-its-lease.md) (slots, the member's disk cap), [ADR-0044](0044-a-lanes-prepared-directories-can-be-linked-into-its-worktree.md), [ADR-0049](0049-a-lanes-need-is-measured-disk-included.md), [ADR-0063](0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md) @@ -187,6 +187,20 @@ service names it (two services of one `node_modules`, a dev server and an end-to-end tool). Entries made before have another key; the sweep removes them. +## Addendum 2026-10-28: a node keeps the member's build artifacts too + +Card approved by the owner on 2026-10-28, in the pull request that built it. +Telemetry showed a lane on a node building every service on its first +start (about 37 s for a .NET + Angular stack), where a local lane reuses +the main tree's artifacts. So a node keeps, beside the member's store of +what `prepare` makes, its build artifacts: `artifacts//` in +the same store, keyed by the build id the lane's daemon computes (watch +paths, build files, build command) and the lane image (its toolchain). A +lane reads it read-only and puts what it built into its outbox, which the +agent takes in; only the member's own lanes see it. Swept and counted like +the rest of the store. A start that finds its artifact there copies it +(`build_reused` with `source: store`) instead of building. + ## What this ADR does not say - That the main working tree uses the store. It runs in place, with the diff --git a/docs/adr/README.md b/docs/adr/README.md index 06003a31..0bae7317 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -140,7 +140,7 @@ stay. | [0059](0059-a-services-stop-command-ends-what-its-run-started.md) | A service's `stop` command ends what its `run` started outside its process tree | Accepted | | [0060](0060-the-tray-is-a-client-of-the-hub.md) | The tray is a client of the hub, a process of its own, on every desktop | Accepted | | [0061](0061-the-dashboard-opens-in-its-installed-app.md) | The dashboard opens in its installed app, when there is one | Accepted | -| [0062](0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md) | What `prepare` makes is kept in a store per machine and repository, keyed by its inputs | Accepted; measured and built on the developer's machine, and on nodes, noted 2026-10-26 | +| [0062](0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md) | What `prepare` makes is kept in a store per machine and repository, keyed by its inputs | Addendum 2026-10-28 (a node keeps the member's build artifacts too); Accepted; measured and built on the developer's machine, and on nodes, noted 2026-10-26 | | [0063](0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md) | A lane on a node links its worktree to a copy from the local store | Accepted; built, noted 2026-10-26; addendum 2026-10-27 (two copies, the link moves when the new one is whole; an emptied copy is prepared again) | | [0064](0064-every-compose-call-is-told-the-lane-it-runs-for.md) | Every Compose call is told the lane it runs for | Accepted; addendum 2026-10-26 (a lane on a node: native `{lane}`, `{lane_suffix}`, `DEVSTACK_LANE` follow its name) | | [0065](0065-the-store-is-warmed-for-a-ref-before-a-lane-needs-it.md) | The store is warmed for a ref before a lane needs it | Accepted; built, noted 2026-10-26 | diff --git a/docs/pool.md b/docs/pool.md index 5d6edcb3..cbaeca13 100644 --- a/docs/pool.md +++ b/docs/pool.md @@ -353,7 +353,9 @@ admitted like a lane, on the ref's checkout as its mirror (its slot is the ref's, `warm--`), its container runs only the `prepare` the member's store there lacks, starts no container of the stack, and the lease ends when it is done. A node before 0.24.0 is not asked (it would start a whole -lane); a node whose policy says `warm = false` refuses it. A member's store of what `prepare` makes +lane); a node whose policy says `warm = false` refuses it. A member's store on a node also keeps its builds' artifacts (keyed by the +build id and the lane image): the member's next lane with the same inputs +copies them instead of building (ADR-0062 addendum). A member's store of what `prepare` makes ([ADR-0062](adr/0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md)), one per repository on the node, counts with its kept lanes: an entry no lane used for as long as a stopped lane is kept goes, and over the room the