From ed00f0b25e5cee10a434f170d18f62a6692681a1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 11 May 2019 00:41:13 +0200 Subject: [PATCH] Cache flake-based jobset evaluations --- src/lib/Hydra/Schema/JobsetEvals.pm | 11 +++++++++-- src/script/hydra-eval-jobset | 15 +++++++++++++-- src/sql/hydra.sql | 2 ++ src/sql/upgrade-57.sql | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Schema/JobsetEvals.pm b/src/lib/Hydra/Schema/JobsetEvals.pm index 0bd21da2..ef0b1523 100644 --- a/src/lib/Hydra/Schema/JobsetEvals.pm +++ b/src/lib/Hydra/Schema/JobsetEvals.pm @@ -88,6 +88,11 @@ __PACKAGE__->table("JobsetEvals"); data_type: 'integer' is_nullable: 1 +=head2 flake + + data_type: 'text' + is_nullable: 1 + =cut __PACKAGE__->add_columns( @@ -111,6 +116,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 1 }, "nrsucceeded", { data_type => "integer", is_nullable => 1 }, + "flake", + { data_type => "text", is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -188,8 +195,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-06-13 01:54:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SlEiF8oN6FBK262uSiMKiw +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2019-05-11 00:16:10 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:XwlJFCJiS0LHsLg2fFqfUg __PACKAGE__->has_many( "buildIds", diff --git a/src/script/hydra-eval-jobset b/src/script/hydra-eval-jobset index 1e5c81e7..71d24a83 100755 --- a/src/script/hydra-eval-jobset +++ b/src/script/hydra-eval-jobset @@ -607,6 +607,16 @@ sub checkJobsetWrapped { }; my $fetchError = $@; + my $flakeRef = $jobset->flake; + if (defined $flakeRef) { + (my $res, my $json, my $stderr) = captureStdoutStderr( + 600, "nix", "flake", "info", "--tarball-ttl", 0, "--json", "--", $flakeRef); + die "'nix flake info' returned " . ($res & 127 ? "signal $res" : "exit code " . ($res >> 8)) + . ":\n" . ($stderr ? decode("utf-8", $stderr) : "(no output)\n") + if $res; + $flakeRef = decode_json($json)->{'uri'}; + } + Net::Statsd::increment("hydra.evaluator.checkouts"); my $checkoutStop = clock_gettime(CLOCK_MONOTONIC); Net::Statsd::timing("hydra.evaluator.checkout_time", int(($checkoutStop - $checkoutStart) * 1000)); @@ -626,7 +636,7 @@ sub checkJobsetWrapped { my @args = ($jobset->nixexprinput, $jobset->nixexprpath, inputsToArgs($inputInfo, $exprType)); my $argsHash = sha256_hex("@args"); my $prevEval = getPrevJobsetEval($db, $jobset, 0); - if (defined $prevEval && $prevEval->hash eq $argsHash && !$dryRun && !$jobset->forceeval) { + if (defined $prevEval && $prevEval->hash eq $argsHash && !$dryRun && !$jobset->forceeval && $prevEval->flake eq $flakeRef) { print STDERR " jobset is unchanged, skipping\n"; Net::Statsd::increment("hydra.evaluator.unchanged_checkouts"); txn_do($db, sub { @@ -637,7 +647,7 @@ sub checkJobsetWrapped { # Evaluate the job expression. my $evalStart = clock_gettime(CLOCK_MONOTONIC); - my $jobs = evalJobs($inputInfo, $exprType, $jobset->nixexprinput, $jobset->nixexprpath, $jobset->flake); + my $jobs = evalJobs($inputInfo, $exprType, $jobset->nixexprinput, $jobset->nixexprpath, $flakeRef); my $evalStop = clock_gettime(CLOCK_MONOTONIC); if ($jobsetsJobset) { @@ -697,6 +707,7 @@ sub checkJobsetWrapped { , evaltime => abs(int($evalStop - $evalStart)) , hasnewbuilds => $jobsetChanged ? 1 : 0 , nrbuilds => $jobsetChanged ? scalar(keys %buildMap) : undef + , flake => $flakeRef }); if ($jobsetChanged) { diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 8998fd57..f81bbad4 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -527,6 +527,8 @@ create table JobsetEvals ( nrBuilds integer, nrSucceeded integer, -- set lazily when all builds are finished + flake text, -- immutable flake reference + foreign key (project) references Projects(name) on delete cascade on update cascade, foreign key (project, jobset) references Jobsets(project, name) on delete cascade on update cascade ); diff --git a/src/sql/upgrade-57.sql b/src/sql/upgrade-57.sql index 15553beb..b59ee949 100644 --- a/src/sql/upgrade-57.sql +++ b/src/sql/upgrade-57.sql @@ -4,3 +4,4 @@ alter table Jobsets add column type integer default 0; alter table Jobsets add column flake text; alter table Jobsets add check ((type = 0) = (nixExprInput is not null and nixExprPath is not null)); alter table Jobsets add check ((type = 1) = (flake is not null)); +alter table JobsetEvals add column flake text;