From 80ff78b1b6ed14e34b3befc24fa5e85128c1be53 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 9 Mar 2016 15:15:12 +0100 Subject: [PATCH] Unify build and step status codes Also remove the obsolete status code 5 from the database. --- src/hydra-queue-runner/builder.cc | 15 ++++------- src/hydra-queue-runner/hydra-queue-runner.cc | 12 ++++----- src/hydra-queue-runner/queue-monitor.cc | 2 +- src/hydra-queue-runner/state.hh | 22 +++++----------- src/root/build.tt | 2 +- src/root/common.tt | 4 +-- src/sql/hydra.sql | 27 ++++++++------------ src/sql/upgrade-46.sql | 5 ++++ 8 files changed, 36 insertions(+), 53 deletions(-) create mode 100644 src/sql/upgrade-46.sql diff --git a/src/hydra-queue-runner/builder.cc b/src/hydra-queue-runner/builder.cc index a338ba0e..a0d076b7 100644 --- a/src/hydra-queue-runner/builder.cc +++ b/src/hydra-queue-runner/builder.cc @@ -116,7 +116,7 @@ State::StepResult State::doBuildStep(nix::ref destStore, Step::ptr step, { auto mc = startDbUpdate(); pqxx::work txn(*conn); - stepNr = createBuildStep(txn, result.startTime, build, step, machine->sshName, bssBusy); + stepNr = createBuildStep(txn, result.startTime, build, step, machine->sshName, bsBusy); txn.commit(); } @@ -171,7 +171,7 @@ State::StepResult State::doBuildStep(nix::ref destStore, Step::ptr step, auto mc = startDbUpdate(); pqxx::work txn(*conn); finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, build->id, - stepNr, machine->sshName, bssAborted, result.errorMsg); + stepNr, machine->sshName, bsAborted, result.errorMsg); txn.commit(); if (quit) exit(1); return sRetry; @@ -222,7 +222,7 @@ State::StepResult State::doBuildStep(nix::ref destStore, Step::ptr step, pqxx::work txn(*conn); finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, - build->id, stepNr, machine->sshName, bssSuccess); + build->id, stepNr, machine->sshName, bsSuccess); for (auto & b : direct) markSucceededBuild(txn, b, res, build != b || result.status != BuildResult::Built, @@ -314,11 +314,6 @@ State::StepResult State::doBuildStep(nix::ref destStore, Step::ptr step, result.status == BuildResult::LogLimitExceeded ? bsLogLimitExceeded : result.canRetry() ? bsAborted : bsFailed; - BuildStepStatus buildStepStatus = - result.status == BuildResult::TimedOut ? bssTimedOut : - result.status == BuildResult::LogLimitExceeded ? bssLogLimitExceeded : - result.canRetry() ? bssAborted : - bssFailed; /* For standard failures, we don't care about the error message. */ @@ -340,12 +335,12 @@ State::StepResult State::doBuildStep(nix::ref destStore, Step::ptr step, build2->finishedInDB) continue; createBuildStep(txn, 0, build2, step, machine->sshName, - buildStepStatus, result.errorMsg, build == build2 ? 0 : build->id); + buildStatus, result.errorMsg, build == build2 ? 0 : build->id); } if (!cachedFailure) finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, - build->id, stepNr, machine->sshName, buildStepStatus, result.errorMsg); + build->id, stepNr, machine->sshName, buildStatus, result.errorMsg); /* Mark all builds that depend on this derivation as failed. */ for (auto & build2 : indirect) { diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 2a21e647..d391b237 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -202,7 +202,7 @@ void State::clearBusy(Connection & conn, time_t stopTime) pqxx::work txn(conn); txn.parameterized ("update BuildSteps set busy = 0, status = $1, stopTime = $2 where busy = 1") - ((int) bssAborted) + ((int) bsAborted) (stopTime, stopTime != 0).exec(); txn.commit(); } @@ -220,7 +220,7 @@ int State::allocBuildStep(pqxx::work & txn, Build::ptr build) int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, Step::ptr step, - const std::string & machine, BuildStepStatus status, const std::string & errorMsg, BuildID propagatedFrom) + const std::string & machine, BuildStatus status, const std::string & errorMsg, BuildID propagatedFrom) { int stepNr = allocBuildStep(txn, build); @@ -230,13 +230,13 @@ int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, (stepNr) (0) // == build (step->drvPath) - (status == bssBusy ? 1 : 0) + (status == bsBusy ? 1 : 0) (startTime, startTime != 0) (step->drv.platform) - ((int) status, status != bssBusy) + ((int) status, status != bsBusy) (propagatedFrom, propagatedFrom != 0) (errorMsg, errorMsg != "") - (startTime, startTime != 0 && status != bssBusy) + (startTime, startTime != 0 && status != bsBusy) (machine).exec(); for (auto & output : step->drv.outputs) @@ -249,7 +249,7 @@ int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, void State::finishBuildStep(pqxx::work & txn, time_t startTime, time_t stopTime, unsigned int overhead, - BuildID buildId, int stepNr, const std::string & machine, BuildStepStatus status, + BuildID buildId, int stepNr, const std::string & machine, BuildStatus status, const std::string & errorMsg, BuildID propagatedFrom) { assert(startTime); diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index 7d0b95a2..5fcccae3 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -205,7 +205,7 @@ bool State::getQueuedBuilds(Connection & conn, ref localStore, } } - createBuildStep(txn, 0, build, r, "", bssCachedFailure, "", propagatedFrom); + createBuildStep(txn, 0, build, r, "", bsCachedFailure, "", propagatedFrom); txn.parameterized ("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $3, isCachedBuild = 1 where id = $1 and finished = 0") (build->id) diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index ab70b52f..49a51924 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -26,27 +26,17 @@ typedef std::chrono::time_point system_time; typedef enum { bsSuccess = 0, bsFailed = 1, - bsDepFailed = 2, + bsDepFailed = 2, // builds only bsAborted = 3, - bsFailedWithOutput = 6, + bsFailedWithOutput = 6, // builds only bsTimedOut = 7, + bsCachedFailure = 8, // steps only bsUnsupported = 9, bsLogLimitExceeded = 10, + bsBusy = 100, // not stored } BuildStatus; -typedef enum { - bssSuccess = 0, - bssFailed = 1, - bssAborted = 4, - bssTimedOut = 7, - bssCachedFailure = 8, - bssUnsupported = 9, - bssLogLimitExceeded = 10, - bssBusy = 100, // not stored -} BuildStepStatus; - - struct RemoteResult : nix::BuildResult { time_t startTime = 0, stopTime = 0; @@ -384,12 +374,12 @@ private: int allocBuildStep(pqxx::work & txn, Build::ptr build); int createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, Step::ptr step, - const std::string & machine, BuildStepStatus status, const std::string & errorMsg = "", + const std::string & machine, BuildStatus status, const std::string & errorMsg = "", BuildID propagatedFrom = 0); void finishBuildStep(pqxx::work & txn, time_t startTime, time_t stopTime, unsigned int overhead, BuildID buildId, int stepNr, - const std::string & machine, BuildStepStatus status, const std::string & errorMsg = "", + const std::string & machine, BuildStatus status, const std::string & errorMsg = "", BuildID propagatedFrom = 0); int createSubstitutionStep(pqxx::work & txn, time_t startTime, time_t stopTime, diff --git a/src/root/build.tt b/src/root/build.tt index 1ed16fd8..20ff4abe 100644 --- a/src/root/build.tt +++ b/src/root/build.tt @@ -55,7 +55,7 @@ FOR step IN steps; IF step.busy; busy = 1; END; END; Building [% ELSIF step.status == 0 %] Succeeded - [% ELSIF step.status == 4 %] + [% ELSIF step.status == 3 %] Aborted[% IF step.errormsg %]: [% HTML.escape(step.errormsg); END %] [% ELSIF step.status == 7 %] Timed out diff --git a/src/root/common.tt b/src/root/common.tt index f844a919..0f629cf7 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -195,7 +195,7 @@ BLOCK renderBuildStatusIcon; Succeeded [% ELSIF buildstatus == 1 %] Failed - [% ELSIF buildstatus == 2 || buildstatus == 5 %] + [% ELSIF buildstatus == 2 %] Dependency failed [% ELSIF buildstatus == 3 || buildstatus == 9 %] Aborted @@ -224,7 +224,7 @@ BLOCK renderStatus; Success [% ELSIF buildstatus == 1 %] Build returned a non-zero exit code - [% ELSIF buildstatus == 2 || buildstatus == 5 %] + [% ELSIF buildstatus == 2 %] A dependency of the build failed [% ELSIF buildstatus == 4 %] Cancelled by user diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index c551e05e..2511a960 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -180,15 +180,16 @@ create table Builds ( -- Information about finished builds. isCachedBuild integer, -- boolean - -- Status codes: + -- Status codes used for builds and steps: -- 0 = succeeded - -- 1 = build of this derivation failed - -- 2 = build of some dependency failed - -- 3 = other failure - -- 4 = build cancelled (removed from queue; never built) - -- 5 = build not done because a dependency failed previously (obsolete) - -- 6 = failure with output - -- 7 = timed out + -- 1 = regular Nix failure (derivation returned non-zero exit code) + -- 2 = build of a dependency failed [builds only] + -- 3 = build or step aborted due to misc failure + -- 4 = build cancelled (removed from queue; never built) [builds only] + -- 5 = [obsolete] + -- 6 = failure with output (i.e. $out/nix-support/failed exists) [builds only] + -- 7 = build timed out + -- 8 = cached failure [steps only; builds use isCachedBuild] -- 9 = unsupported system type -- 10 = log limit exceeded buildStatus integer, @@ -253,15 +254,7 @@ create table BuildSteps ( busy integer not null, - -- Status codes: - -- 0 = succeeded - -- 1 = failed normally - -- 4 = aborted - -- 7 = timed out - -- 8 = cached failure - -- 9 = unsupported system type - -- 10 = log limit exceeded - status integer, + status integer, -- see Builds.buildStatus errorMsg text, diff --git a/src/sql/upgrade-46.sql b/src/sql/upgrade-46.sql new file mode 100644 index 00000000..bc0f9da2 --- /dev/null +++ b/src/sql/upgrade-46.sql @@ -0,0 +1,5 @@ +-- Unify Builds and BuildSteps status codes. +update BuildSteps set status = 3 where status = 4; + +-- Get rid of obsolete status code 5. +update Builds set isCachedBuild = 1, buildStatus = 2 where buildStatus = 5;