From 1868d3af0bfebc4dbcd070a68f0333c58bc3869d Mon Sep 17 00:00:00 2001 From: ajs124 Date: Sun, 12 Jun 2022 17:48:38 +0200 Subject: [PATCH 1/2] sql: migrate timestamps from 4 to 8 bytes --- src/sql/hydra.sql | 38 +++++++++++++++++++------------------- src/sql/upgrade-83.sql | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 src/sql/upgrade-83.sql diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index eaae6da3a..768f9c512 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -74,9 +74,9 @@ create table Jobsets ( nixExprInput text, -- name of the jobsetInput containing the Nix or Guix expression nixExprPath text, -- relative path of the Nix or Guix expression errorMsg text, -- used to signal the last evaluation error etc. for this jobset - errorTime integer, -- timestamp associated with errorMsg - lastCheckedTime integer, -- last time the evaluator looked at this jobset - triggerTime integer, -- set if we were triggered by a push event + errorTime bigint, -- timestamp associated with errorMsg + lastCheckedTime bigint, -- last time the evaluator looked at this jobset + triggerTime bigint, -- set if we were triggered by a push event enabled integer not null default 1, -- 0 = disabled, 1 = enabled, 2 = one-shot, 3 = one-at-a-time enableEmail integer not null default 1, hidden integer not null default 0, @@ -86,7 +86,7 @@ create table Jobsets ( schedulingShares integer not null default 100, fetchErrorMsg text, forceEval boolean, - startTime integer, -- if jobset is currently running + startTime bigint, -- if jobset is currently running type integer not null default 0, -- 0 == legacy, 1 == flake flake text, enable_dynamic_run_command boolean not null default false, @@ -161,7 +161,7 @@ create table Builds ( finished integer not null, -- 0 = scheduled, 1 = finished - timestamp integer not null, -- time this build was added + timestamp bigint not null, -- time this build was added -- Info about the inputs. jobset_id integer not null, @@ -190,8 +190,8 @@ create table Builds ( globalPriority integer not null default 0, -- FIXME: remove startTime? - startTime integer, -- if busy/finished, time we started - stopTime integer, -- if finished, time we finished + startTime bigint, -- if busy/finished, time we started + stopTime bigint, -- if finished, time we finished -- Information about finished builds. isCachedBuild integer, -- boolean @@ -276,8 +276,8 @@ create table BuildSteps ( errorMsg text, - startTime integer, - stopTime integer, + startTime bigint, + stopTime bigint, machine text not null default '', system text, @@ -362,7 +362,7 @@ create table BuildMetrics ( project text not null, jobset text not null, job text not null, - timestamp integer not null, + timestamp bigint not null, primary key (build, name), foreign key (build) references Builds(id) on delete cascade, @@ -376,8 +376,8 @@ create table BuildMetrics ( -- the timestamp when we first saw the path have these contents. create table CachedPathInputs ( srcPath text not null, - timestamp integer not null, -- when we first saw this hash - lastSeen integer not null, -- when we last saw this hash + timestamp bigint not null, -- when we first saw this hash + lastSeen bigint not null, -- when we last saw this hash sha256hash text not null, storePath text not null, primary key (srcPath, sha256hash) @@ -431,8 +431,8 @@ create table CachedHgInputs ( create table CachedCVSInputs ( uri text not null, module text not null, - timestamp integer not null, -- when we first saw this hash - lastSeen integer not null, -- when we last saw this hash + timestamp bigint not null, -- when we first saw this hash + lastSeen bigint not null, -- when we last saw this hash sha256hash text not null, storePath text not null, primary key (uri, module, sha256hash) @@ -441,7 +441,7 @@ create table CachedCVSInputs ( create table EvaluationErrors ( id serial primary key not null, errorMsg text, -- error output from the evaluator - errorTime integer -- timestamp associated with errorMsg + errorTime bigint -- timestamp associated with errorMsg ); create table JobsetEvals ( @@ -450,7 +450,7 @@ create table JobsetEvals ( evaluationerror_id integer, - timestamp integer not null, -- when this entry was added + timestamp bigint not null, -- when this entry was added checkoutTime integer not null, -- how long obtaining the inputs took (in seconds) evalTime integer not null, -- how long evaluation took (in seconds) @@ -520,7 +520,7 @@ create table UriRevMapper ( create table NewsItems ( id serial primary key not null, contents text not null, - createTime integer not null, + createTime bigint not null, author text not null, foreign key (author) references Users(userName) on delete cascade on update cascade ); @@ -577,8 +577,8 @@ create table RunCommandLogs ( -- can we do this in a principled way? a build can be part of many evaluations -- but a "bug" of RunCommand, imho, is that it should probably run per evaluation? command text not null, - start_time integer, - end_time integer, + start_time bigint, + end_time bigint, error_number integer, exit_code integer, signal integer, diff --git a/src/sql/upgrade-83.sql b/src/sql/upgrade-83.sql new file mode 100644 index 000000000..636b42452 --- /dev/null +++ b/src/sql/upgrade-83.sql @@ -0,0 +1,27 @@ +ALTER TABLE Jobsets ALTER COLUMN errorTime TYPE BIGINT; +ALTER TABLE Jobsets ALTER COLUMN lastCheckedTime TYPE BIGINT; + +DROP TRIGGER IF EXISTS JobsetSchedulingChanged ON Jobsets; +ALTER TABLE Jobsets ALTER COLUMN triggerTime TYPE BIGINT; +create trigger JobsetSchedulingChanged after update on Jobsets for each row + when (((old.triggerTime is distinct from new.triggerTime) and (new.triggerTime is not null)) + or (old.checkInterval != new.checkInterval) + or (old.enabled != new.enabled)) + execute procedure notifyJobsetSchedulingChanged(); + +ALTER TABLE Jobsets ALTER COLUMN startTime TYPE BIGINT; +ALTER TABLE Builds ALTER COLUMN timestamp TYPE BIGINT; +ALTER TABLE Builds ALTER COLUMN startTime TYPE BIGINT; +ALTER TABLE Builds ALTER COLUMN stopTime TYPE BIGINT; +ALTER TABLE BuildSteps ALTER COLUMN startTime TYPE BIGINT; +ALTER TABLE BuildSteps ALTER COLUMN stopTime TYPE BIGINT; +ALTER TABLE BuildMetrics ALTER COLUMN timestamp TYPE BIGINT; +ALTER TABLE CachedPathInputs ALTER COLUMN timestamp TYPE BIGINT; +ALTER TABLE CachedPathInputs ALTER COLUMN lastSeen TYPE BIGINT; +ALTER TABLE CachedCVSInputs ALTER COLUMN timestamp TYPE BIGINT; +ALTER TABLE CachedCVSInputs ALTER COLUMN lastSeen TYPE BIGINT; +ALTER TABLE EvaluationErrors ALTER COLUMN errorTime TYPE BIGINT; +ALTER TABLE JobsetEvals ALTER COLUMN timestamp TYPE BIGINT; +ALTER TABLE NewsItems ALTER COLUMN createTime TYPE BIGINT; +ALTER TABLE RunCommandLogs ALTER COLUMN start_time TYPE BIGINT; +ALTER TABLE RunCommandLogs ALTER COLUMN end_time TYPE BIGINT; From b6d2a3d8070edf71b9dfe44dfd9f03acab6b4d29 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Sun, 12 Jun 2022 20:50:17 +0200 Subject: [PATCH 2/2] WIP: queue-monitor: try some stuff --- src/hydra-queue-runner/queue-monitor.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index 3bde0d998..43a79ca33 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -153,7 +153,7 @@ bool State::getQueuedBuilds(Connection & conn, auto mc = startDbUpdate(); pqxx::work txn(conn); txn.exec_params0 - ("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $3 where id = $1 and finished = 0", + ("update Builds set finished = 1, buildStatus = $2, startTime = $3::bigint, stopTime = $3::bigint where id = $1 and finished = 0", build->id, (int) bsAborted, time(0)); @@ -207,7 +207,7 @@ bool State::getQueuedBuilds(Connection & conn, createBuildStep(txn, 0, build->id, ex.step, "", bsCachedFailure, "", propagatedFrom); txn.exec_params - ("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $3, isCachedBuild = 1, notificationPendingSince = $3 " + ("update Builds set finished = 1, buildStatus = $2, startTime = $3::bigint, stopTime = $3::bigint, isCachedBuild = 1, notificationPendingSince = $3 " "where id = $1 and finished = 0", build->id, (int) (ex.step->drvPath == build->drvPath ? bsFailed : bsDepFailed),