Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ and listed with their assets on the

### Fixed

- **`devstack up --workers` runs the workers of a lane on a node too**
(#314): the flag never reached the node, so a worker gated by
`{is_main}` stayed off there and its jobs stayed queued, with nothing
saying so. It goes with the lane's start to the node's agent and its
daemon (a profile's `workers` too), stays with the lane when it moves or
the stack restarts, and `devstack lane list` says which lanes run their
workers. A node before this release does not take it: `up` warns.
`up --workers` on a lane that runs already says it applies at its next
start, on a node as here.

- **A lane's memory check looks at Docker Desktop's VM** (#309): on Windows
and macOS the check compared the whole need with the host's free memory,
while the containers run in Docker Desktop's VM with a limit of its own;
Expand Down
8 changes: 7 additions & 1 deletion crates/devstack-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,13 @@ async fn lanes_start(State(s): State<AppState>, Json(body): Json<LaneStart>) ->
if let Some(on) = body.on.as_deref().filter(|o| !o.trim().is_empty()) {
// What a local lane would need here is what it needs there.
let need = lane_estimate(&main, &usage);
return match lanes.activate_remote(&body.path, on.trim(), need, profile)? {
return match lanes.activate_remote(
&body.path,
on.trim(),
need,
profile,
body.workers,
)? {
crate::lanes::RemoteStart::Running(name) => {
view(&name).map(|v| (StatusCode::CREATED, v))
}
Expand Down
52 changes: 50 additions & 2 deletions crates/devstack-daemon/src/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ pub struct LaneView {
/// `*` for every member; empty: nobody.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub shared_with: Vec<String>,
/// Its background workers run (`--workers` or its profile, #314), while
/// it runs.
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub workers: bool,
/// The profile it runs with (ADR-0041), while it runs.
#[serde(skip_serializing_if = "Option::is_none")]
pub profile: Option<String>,
Expand Down Expand Up @@ -355,6 +359,9 @@ pub struct Lanes {
shares: Mutex<BTreeMap<String, Vec<String>>>,
/// The profile each started lane runs with (ADR-0041), while it runs.
profiles: Mutex<BTreeMap<String, String>>,
/// The lanes on nodes that run their background workers (`--workers`,
/// #314): a lane here keeps it in its supervisor.
workers: Mutex<BTreeSet<String>>,
/// One main-slot hand-over at a time, and what it took from the main tree.
handover: Mutex<Handover>,
/// One [`Lanes::sync`] at a time: asking git and applying the answer go
Expand Down Expand Up @@ -397,6 +404,9 @@ struct CarriedLane {
name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
profile: Option<String>,
/// Its background workers run (#314).
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
workers: bool,
/// On a node: its lease and ports; absent: it ran on this machine.
#[serde(default, skip_serializing_if = "Option::is_none")]
node: Option<crate::remote::Carried>,
Expand Down Expand Up @@ -847,6 +857,7 @@ impl Lanes {
forgetting: Mutex::new(BTreeSet::new()),
shares: Mutex::new(shares),
profiles: Mutex::new(BTreeMap::new()),
workers: Mutex::new(BTreeSet::new()),
handover: Mutex::new(Handover::default()),
syncing: Mutex::new(()),
missing: Mutex::new(BTreeMap::new()),
Expand Down Expand Up @@ -1231,6 +1242,7 @@ impl Lanes {
forward: false,
step: &|_, _| {},
profile: None,
workers: false,
warm: true,
files: Some(&checkout.1),
};
Expand Down Expand Up @@ -1503,6 +1515,7 @@ impl Lanes {
self.unlink_node(name);
self.missing.lock().unwrap().remove(name);
self.profiles.lock().unwrap().remove(name);
self.workers.lock().unwrap().remove(name);
// Logged there; a lane that is forgotten has nobody to tell.
let _ = self.remove_infra(name);
// Its kept data on the nodes it ran on goes too (ADR-0038 point 4);
Expand Down Expand Up @@ -1979,6 +1992,13 @@ impl Lanes {
pool: on_node.map(|r| r.pool.clone()),
shared_with: self.share_of(&k.entry.name),
profile: self.profiles.lock().unwrap().get(&k.entry.name).cloned(),
workers: lane.map_or_else(
|| {
on_node.is_some()
&& self.workers.lock().unwrap().contains(&k.entry.name)
},
|l| l.sup.lane_workers(),
),
node_error: node_state.as_ref().and_then(|st| st.error()),
not_forwarded: node_state
.as_ref()
Expand Down Expand Up @@ -2129,6 +2149,7 @@ impl Lanes {
let t0 = std::time::Instant::now();
// A profile holds while the lane runs (ADR-0041).
self.profiles.lock().unwrap().remove(name);
self.workers.lock().unwrap().remove(name);
// Stopped: a start or move that failed before is no longer news.
self.forget_failed(Some(name));
let remote = self.remote.lock().unwrap().remove(name);
Expand Down Expand Up @@ -2587,14 +2608,16 @@ impl Lanes {
/// the main ports. A start or move under way is not carried.
fn carry_now(&self) -> Carry {
let profiles = self.profiles.lock().unwrap().clone();
let workers = self.workers.lock().unwrap().clone();
let mut lanes: Vec<CarriedLane> = self
.map
.lock()
.unwrap()
.keys()
.map(|n| CarriedLane {
.iter()
.map(|(n, l)| CarriedLane {
name: n.clone(),
profile: profiles.get(n).cloned(),
workers: l.sup.lane_workers(),
node: None,
})
.collect();
Expand All @@ -2607,6 +2630,7 @@ impl Lanes {
.map(|(n, r)| CarriedLane {
name: n.clone(),
profile: profiles.get(n).cloned(),
workers: workers.contains(n),
node: Some(r.carried()),
}),
);
Expand Down Expand Up @@ -2796,6 +2820,9 @@ impl Lanes {
.unwrap()
.insert(l.name.clone(), p.clone());
}
if l.workers {
self.workers.lock().unwrap().insert(l.name.clone());
}
let lease = c.lease.clone();
let adopted = crate::remote::RemoteLane::adopt(
&self.rt,
Expand All @@ -2819,6 +2846,7 @@ impl Lanes {
}
Err(e) => {
self.profiles.lock().unwrap().remove(&l.name);
self.workers.lock().unwrap().remove(&l.name);
// Said here: not again as a lane nobody followed.
crate::remote::forget_followed(&self.state_dir(&l.name), &lease);
self.not_carried(&l.name, "remote", &node, &e);
Expand Down Expand Up @@ -2860,6 +2888,7 @@ impl Lanes {
// `up`, and the lane runs the rest.
match self.activate(&path, l.profile.as_deref()) {
Ok(lane) => {
lane.sup.set_lane_workers(l.workers);
let failed = lane.sup.up().err();
crate::diag::info(
"lane_carried",
Expand Down Expand Up @@ -2995,6 +3024,7 @@ impl Lanes {
on: &str,
need: crate::remote::Expected,
profile: Option<&str>,
workers: bool,
) -> Result<RemoteStart, String> {
let path = std::path::absolute(path).map_err(|e| e.to_string())?;
if same_tree(&path, &self.main.repo) {
Expand Down Expand Up @@ -3056,6 +3086,11 @@ impl Lanes {
.insert(name.clone(), p.to_string()),
None => self.profiles.lock().unwrap().remove(&name),
};
if workers {
self.workers.lock().unwrap().insert(name.clone());
} else {
self.workers.lock().unwrap().remove(&name);
}
self.begin_move(&name, "start", on, 3);
let leased = {
let step = self.step_fn(&name);
Expand Down Expand Up @@ -3227,6 +3262,7 @@ impl Lanes {
let synced = self.synced();
let scratch = self.state_dir(&entry.name).join("remote");
let profile = self.profiles.lock().unwrap().get(&entry.name).cloned();
let workers = self.workers.lock().unwrap().contains(&entry.name);
// What the lane's own stack file declares it needs at least, with
// its profile (ADR-0049 point 5); the main tree's where it does not
// load.
Expand Down Expand Up @@ -3259,6 +3295,7 @@ impl Lanes {
forward,
step,
profile: profile.as_deref(),
workers,
warm: false,
files: None,
})
Expand Down Expand Up @@ -3320,6 +3357,15 @@ impl Lanes {
if here && local.is_some() {
return Ok(());
}
// Its workers go with it to a node (#314).
if let Some(l) = &local {
let mut w = self.workers.lock().unwrap();
if l.sup.lane_workers() {
w.insert(name.to_string());
} else {
w.remove(name);
}
}
if let Some(r) = &remote
&& !here
&& r.is_at(to)
Expand Down Expand Up @@ -3411,9 +3457,11 @@ impl Lanes {
self.pending.lock().unwrap().remove(name);
step(2, "starting it here (build, infrastructure, services)");
let profile = self.profiles.lock().unwrap().get(name).cloned();
let workers = self.workers.lock().unwrap().contains(name);
let started = self
.activate(&entry.path, profile.as_deref())
.and_then(|lane| {
lane.sup.set_lane_workers(workers);
lane.sup.up().inspect_err(|_| {
lane.sup.down(true);
let removed = self.map.lock().unwrap().remove(name);
Expand Down
8 changes: 8 additions & 0 deletions crates/devstack-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ pub fn serve(stack_file: &Path) -> Result<(), String> {
rt.handle().clone(),
)?;
sup.refresh_infra();
// A lane on a node runs its background workers as its requester asked
// (`--workers`, `DEVSTACK_LANE_WORKERS`), or as its profile says, as a
// lane here does (#314).
if remote_lane() {
let asked = std::env::var_os("DEVSTACK_LANE_WORKERS").is_some_and(|v| v == "1");
let profile = sup.stack.profile.as_ref().and_then(|p| p.workers);
sup.set_lane_workers(profile.unwrap_or(asked));
}
let usage = usage::Sampler::start(sup.clone());
// Kept for the daemon's lifetime; changes become candidates (ADR-0003).
let _watcher = watch::start(sup.clone());
Expand Down
27 changes: 26 additions & 1 deletion crates/devstack-daemon/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ pub struct RemoteSpec<'a> {
pub step: &'a (dyn Fn(u8, &str) + Send + Sync),
/// The profile it runs with (ADR-0041).
pub profile: Option<&'a str>,
/// Its background workers run (`devstack up --workers`, #314).
pub workers: bool,
/// A warm lease (ADR-0065 point 5): only `prepare`, no infrastructure.
pub warm: bool,
/// The files of `worktree` to sync, when git cannot tell them: a ref's
Expand Down Expand Up @@ -603,7 +605,20 @@ impl RemoteLane {
// refused it already): refused here, before anything is admitted.
// Another release, or one that does not say, is a warning
// (ADR-0031 point 8).
let warning = release_warning(&offer).map_err(|e| format!("lane `{}`: {e}", spec.name))?;
let mut warning =
release_warning(&offer).map_err(|e| format!("lane `{}`: {e}", spec.name))?;
// An agent before 0.25.1 does not pass `--workers` on (#314).
if spec.workers && !takes_workers(offer.node.devstack.as_ref()) {
let w = format!(
"the node {} runs {}, which starts the lane without its background workers whatever `--workers` says; `devstack up --workers --on local` runs them here",
offer.node.name,
version::describe(offer.node.devstack.as_ref())
);
warning = Some(match warning {
Some(o) => format!("{o}; {w}"),
None => w,
});
}
// What the lease holds, and from what (ADR-0049 point 10).
if let Some(n) = &offer.need {
let from = offer.need_from.as_deref().unwrap_or("");
Expand Down Expand Up @@ -752,6 +767,7 @@ impl RemoteLane {
0,
None,
false,
false,
Duration::from_secs(1800),
&|_| {},
&|_, _| {},
Expand Down Expand Up @@ -808,6 +824,7 @@ impl RemoteLane {
forward,
step,
profile,
workers,
..
} = spec;
let Leased {
Expand Down Expand Up @@ -897,6 +914,7 @@ impl RemoteLane {
// This machine relays UDP (ADR-0056); an older node
// does not read it, and its lane names none.
true,
workers,
Duration::from_secs(1800),
&|p| {
step(3, &format!("on {node}: {p}"));
Expand Down Expand Up @@ -1957,6 +1975,13 @@ fn release_warning(
Ok((!notes.is_empty()).then(|| notes.join("; ")))
}

/// A node's agent passes `--workers` on to its lane (#314): 0.25.1 and
/// later. One that does not say counts as older.
fn takes_workers(node: Option<&devstack_node::version::Release>) -> bool {
node.and_then(|r| devstack_config::version_triple(&r.version))
.is_some_and(|v| v >= (0, 25, 1))
}

/// The warning of a lane a daemon before this one followed (ADR-0052), made
/// against this machine's release: the daemon that leased it compared with
/// its own (`this machine devstack 0.19.0` after an update to 0.20.0). The
Expand Down
5 changes: 5 additions & 0 deletions crates/devstack-daemon/src/supervisor/handover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ impl Supervisor {
self.lane_workers.store(on, Ordering::SeqCst);
}

/// What [`Self::set_lane_workers`] said last.
pub fn lane_workers(&self) -> bool {
self.lane_workers.load(Ordering::SeqCst)
}

/// Main lane: the lane serving its fixed ports, if one does (`None` in a
/// lane: its own ports are its own).
pub fn served_by(&self) -> Option<String> {
Expand Down
6 changes: 6 additions & 0 deletions crates/devstack-node/src/lanerun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct LaneRun {
/// Its requester relays UDP ports (ADR-0056): the lane's daemon is told,
/// and the start answers with them.
pub relay_udp: bool,
/// Its background workers run (`DEVSTACK_LANE_WORKERS`, #314).
pub workers: bool,
/// The memory limit of each of its containers (ADR-0033), bytes.
pub memory_limit: Option<u64>,
/// Their CPU limit, cores.
Expand Down Expand Up @@ -964,6 +966,9 @@ impl LaneRun {
if self.warm {
args.extend(["-e", "DEVSTACK_WARM=1"]);
}
if self.workers {
args.extend(["-e", "DEVSTACK_LANE_WORKERS=1"]);
}
if let Some(n) = networks.first() {
args.extend(["--network", n.as_str()]);
}
Expand Down Expand Up @@ -1360,6 +1365,7 @@ mod tests {
port_offset: 100,
profile: None,
relay_udp: false,
workers: false,
memory_limit: None,
cpu_limit: None,
network: Network::Lan,
Expand Down
11 changes: 9 additions & 2 deletions crates/devstack-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ impl Inner {
port_offset: 0,
profile: None,
relay_udp: false,
workers: false,
memory_limit: None,
cpu_limit: None,
network: crate::policy::Network::Lan,
Expand Down Expand Up @@ -2118,6 +2119,10 @@ pub struct Start {
/// does not send it, an older agent does not read it.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub relay_udp: bool,
/// Its background workers run (`devstack up --workers`, #314); its
/// profile may say so too. An older agent does not read it.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub workers: bool,
}

fn default_stack_file() -> String {
Expand Down Expand Up @@ -2178,15 +2183,16 @@ async fn start(
format!("{} cannot run lanes: its agent is no Linux build", s.name),
));
};
let (stack_file, display_root, port_offset, profile, relay_udp) = body.map_or_else(
|| (default_stack_file(), None, 0, None, false),
let (stack_file, display_root, port_offset, profile, relay_udp, workers) = body.map_or_else(
|| (default_stack_file(), None, 0, None, false, false),
|Json(b)| {
(
b.stack_file,
b.display_root,
b.port_offset,
b.profile,
b.relay_udp,
b.workers,
)
},
);
Expand Down Expand Up @@ -2271,6 +2277,7 @@ async fn start(
run.port_offset = port_offset;
run.profile = profile;
run.relay_udp = relay_udp;
run.workers = workers;
let policies = s2.policies();
let all: Vec<&crate::policy::NodePolicy> = policies.iter().collect();
if let Some(p) = crate::policy::NodePolicy::strictest(&all) {
Expand Down
Loading
Loading