From 72c31100026476a4c62b4ba1459049d0e9f3a580 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 9 Jan 2022 08:58:36 -0500 Subject: [PATCH] queue-runner: track jobsets by ID --- src/hydra-queue-runner/queue-monitor.cc | 22 ++++++++++++---------- src/hydra-queue-runner/state.hh | 5 ++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index 2abf3121..49caf8e3 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -96,8 +96,11 @@ bool State::getQueuedBuilds(Connection & conn, pqxx::work txn(conn); auto res = txn.exec_params - ("select id, project, jobset, job, drvPath, maxsilent, timeout, timestamp, globalPriority, priority from Builds " - "where id > $1 and finished = 0 order by globalPriority desc, id", + ("select builds.id, builds.jobset_id, jobsets.project as project, " + "jobsets.name as jobset, job, drvPath, maxsilent, timeout, timestamp, " + "globalPriority, priority from Builds " + "inner join jobsets on builds.jobset_id = jobsets.id " + "where builds.id > $1 and finished = 0 order by globalPriority desc, builds.id", lastBuildId); for (auto const & row : res) { @@ -110,6 +113,7 @@ bool State::getQueuedBuilds(Connection & conn, auto build = std::make_shared( localStore->parseStorePath(row["drvPath"].as())); build->id = id; + build->jobsetId = row["jobset_id"].as(); build->projectName = row["project"].as(); build->jobsetName = row["jobset"].as(); build->jobName = row["job"].as(); @@ -118,7 +122,7 @@ bool State::getQueuedBuilds(Connection & conn, build->timestamp = row["timestamp"].as(); build->globalPriority = row["globalPriority"].as(); build->localPriority = row["priority"].as(); - build->jobset = createJobset(txn, build->projectName, build->jobsetName); + build->jobset = createJobset(txn, build->projectName, build->jobsetName, build->jobsetId); newIDs.push_back(id); newBuildsByID[id] = build; @@ -569,7 +573,7 @@ Step::ptr State::createStep(ref destStore, Jobset::ptr State::createJobset(pqxx::work & txn, - const std::string & projectName, const std::string & jobsetName) + const std::string & projectName, const std::string & jobsetName, const JobsetID jobsetID) { auto p = std::make_pair(projectName, jobsetName); @@ -580,9 +584,8 @@ Jobset::ptr State::createJobset(pqxx::work & txn, } auto res = txn.exec_params1 - ("select schedulingShares from Jobsets where project = $1 and name = $2", - projectName, - jobsetName); + ("select schedulingShares from Jobsets where id = $1", + jobsetID); if (res.empty()) throw Error("missing jobset - can't happen"); auto shares = res["schedulingShares"].as(); @@ -593,10 +596,9 @@ Jobset::ptr State::createJobset(pqxx::work & txn, /* Load the build steps from the last 24 hours. */ auto res2 = txn.exec_params ("select s.startTime, s.stopTime from BuildSteps s join Builds b on build = id " - "where s.startTime is not null and s.stopTime > $1 and project = $2 and jobset = $3", + "where s.startTime is not null and s.stopTime > $1 and jobset_id = $2", time(0) - Jobset::schedulingWindow * 10, - projectName, - jobsetName); + jobsetID); for (auto const & row : res2) { time_t startTime = row["startTime"].as(); time_t stopTime = row["stopTime"].as(); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index 5a5c5f94..1eed5a84 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -19,6 +19,8 @@ typedef unsigned int BuildID; +typedef unsigned int JobsetID; + typedef std::chrono::time_point system_time; typedef std::atomic counter; @@ -123,6 +125,7 @@ struct Build BuildID id; nix::StorePath drvPath; std::map outputs; + JobsetID jobsetId; std::string projectName, jobsetName, jobName; time_t timestamp; unsigned int maxSilentTime, buildTimeout; @@ -489,7 +492,7 @@ private: bool & stepFinished); Jobset::ptr createJobset(pqxx::work & txn, - const std::string & projectName, const std::string & jobsetName); + const std::string & projectName, const std::string & jobsetName, const JobsetID); void processJobsetSharesChange(Connection & conn);