Skip to content

sql: migrate timestamps from 4 to 8 bytes #1221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/hydra-queue-runner/queue-monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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),
Expand Down
38 changes: 19 additions & 19 deletions src/sql/hydra.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -276,8 +276,8 @@ create table BuildSteps (

errorMsg text,

startTime integer,
stopTime integer,
startTime bigint,
stopTime bigint,

machine text not null default '',
system text,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 (
Expand All @@ -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)

Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions src/sql/upgrade-83.sql
Original file line number Diff line number Diff line change
@@ -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;