From 7846cd6b86c5c63456cb6b67cd41fdb5dbf9d072 Mon Sep 17 00:00:00 2001 From: Stuart Axelbrooke Date: Sun, 23 Nov 2025 11:48:44 +0800 Subject: [PATCH] record building partitions to enable more accurate want state setting --- databuild/build_state.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/databuild/build_state.rs b/databuild/build_state.rs index 27a5c35..b043098 100644 --- a/databuild/build_state.rs +++ b/databuild/build_state.rs @@ -1151,10 +1151,10 @@ impl BuildState { } /** - Wants are schedulable when their partition is live and not tainted + Wants are schedulable when their upstreams are ready and target partitions are not already building */ pub fn want_schedulability(&self, want: &WantDetail) -> WantSchedulability { - // Use type-safe partition checks from partitions + // Check upstream partition statuses (dependencies) let mut live: Vec = Vec::new(); let mut tainted: Vec = Vec::new(); let mut missing: Vec = Vec::new(); @@ -1178,12 +1178,24 @@ impl BuildState { } } + // Check target partition statuses (what this want is trying to build) + // If any target partition is already Building, this want should wait + let mut building: Vec = Vec::new(); + for target_ref in &want.partitions { + if let Some(partition) = self.partitions.get(&target_ref.r#ref) { + if let Partition::Building(p) = partition { + building.push(p.get_ref()); + } + } + } + WantSchedulability { want: want.clone(), status: WantUpstreamStatus { live, tainted, missing, + building, }, } } @@ -1206,6 +1218,8 @@ pub struct WantUpstreamStatus { pub live: Vec, pub tainted: Vec, pub missing: Vec, + /// Target partitions that are currently being built by another job + pub building: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] @@ -1231,7 +1245,13 @@ impl WantsSchedulability { impl WantSchedulability { pub fn is_schedulable(&self) -> bool { - self.status.missing.is_empty() && self.status.tainted.is_empty() + // Want is schedulable if: + // - No missing upstream dependencies + // - No tainted upstream dependencies + // - No target partitions currently being built by another job + self.status.missing.is_empty() + && self.status.tainted.is_empty() + && self.status.building.is_empty() } }