From 4cf0d7c4b30f421e4347bfe2372ccec2639edaf4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Apr 2014 17:54:11 +0200 Subject: [PATCH] hydra-update-gc-roots: Keep derivations of failed builds By keeping the derivations of failed builds in the most recent evaluations, we ensure that failed builds can be restarted. --- src/script/hydra-update-gc-roots | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/script/hydra-update-gc-roots b/src/script/hydra-update-gc-roots index 1efbc69b..69e7cf20 100755 --- a/src/script/hydra-update-gc-roots +++ b/src/script/hydra-update-gc-roots @@ -21,22 +21,24 @@ sub addRoot { } -my @columns = ( "id", "project", "jobset", "job", "system", "finished", "drvpath", "timestamp" ); +my @columns = ( "id", "project", "jobset", "job", "system", "finished", "drvpath", "timestamp", "buildstatus" ); sub keepBuild { - my ($build) = @_; + my ($build, $keepFailedDrvs) = @_; print STDERR " keeping ", ($build->finished ? "" : "scheduled "), "build ", $build->id, " (", $build->get_column('project'), ":", $build->get_column('jobset'), ":", $build->get_column('job'), "; ", $build->system, "; ", strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n"; - foreach my $out ($build->buildoutputs->all) { - if (isValidPath($out->path)) { - addRoot $out->path; - } else { - print STDERR " warning: output ", $out->path, " has disappeared\n" if $build->finished; + if ($build->finished && ($build->buildstatus == 0 || $build->buildstatus == 6)) { + foreach my $out ($build->buildoutputs->all) { + if (isValidPath($out->path)) { + addRoot $out->path; + } else { + print STDERR " warning: output ", $out->path, " has disappeared\n" if $build->finished; + } } } - if (!$build->finished) { + if (!$build->finished || ($keepFailedDrvs && $build->buildstatus != 0)) { if (isValidPath($build->drvpath)) { addRoot $build->drvpath; } else { @@ -58,12 +60,12 @@ closedir DIR; # For scheduled builds, we register the derivation as a GC root. print STDERR "*** looking for scheduled builds\n"; -keepBuild $_ foreach $db->resultset('Builds')->search({ finished => 0 }, { columns => [ @columns ] }); +keepBuild($_, 0) foreach $db->resultset('Builds')->search({ finished => 0 }, { columns => [ @columns ] }); # Keep every build in every release of every project. print STDERR "*** looking for release members\n"; -keepBuild $_ foreach $db->resultset('Builds')->search_literal( +keepBuild($_, 0) foreach $db->resultset('Builds')->search_literal( "exists (select 1 from releasemembers where build = me.id)", { order_by => ["project", "jobset", "job", "id"], columns => [ @columns ] }); @@ -72,7 +74,7 @@ keepBuild $_ foreach $db->resultset('Builds')->search_literal( print STDERR "*** looking for kept builds\n"; my @buildsToKeep = $db->resultset('Builds')->search( { finished => 1, keep => 1 }, { order_by => ["project", "jobset", "job", "id"], columns => [ @columns ] }); -keepBuild $_ foreach @buildsToKeep; +keepBuild($_, 0) foreach @buildsToKeep; # Go over all projects. @@ -107,9 +109,8 @@ foreach my $project ($db->resultset('Projects')->search({}, { order_by => ["name , order_by => "id desc", rows => $keepnr }); } - keepBuild $_ foreach $jobset->builds->search( - { finished => 1, buildStatus => { -in => [0, 6] } - , id => { -in => $db->resultset('JobsetEvalMembers')->search({ eval => { -in => [@evals] } }, { select => "build" })->as_query } + keepBuild($_, 1) foreach $jobset->builds->search( + { id => { -in => $db->resultset('JobsetEvalMembers')->search({ eval => { -in => [@evals] } }, { select => "build" })->as_query } }, { order_by => ["job", "id"], columns => [ @columns ] }); }