* Register builds as GC roots so they don't get deleted.
This commit is contained in:
parent
dcacf2c790
commit
66602def16
@ -2,11 +2,13 @@ package Hydra::Helper::Nix;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
|
use File::Path;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT = qw(
|
our @EXPORT = qw(
|
||||||
isValidPath getHydraPath getHydraDBPath openHydraDB
|
isValidPath getHydraPath getHydraDBPath openHydraDB
|
||||||
|
registerRoot getGCRootsDir
|
||||||
getPrimaryBuildsForReleaseSet getRelease getLatestSuccessfulRelease );
|
getPrimaryBuildsForReleaseSet getRelease getLatestSuccessfulRelease );
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +44,28 @@ sub openHydraDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub getGCRootsDir {
|
||||||
|
die unless defined $ENV{LOGNAME};
|
||||||
|
return "/nix/var/nix/gcroots/per-user/$ENV{LOGNAME}/hydra-roots";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub registerRoot {
|
||||||
|
my ($path) = @_;
|
||||||
|
|
||||||
|
my $gcRootsDir = getGCRootsDir;
|
||||||
|
|
||||||
|
mkpath($gcRootsDir) if !-e $gcRootsDir;
|
||||||
|
|
||||||
|
my $link = "$gcRootsDir/" . basename $path;
|
||||||
|
|
||||||
|
if (!-l $link) {
|
||||||
|
symlink($path, $link)
|
||||||
|
or die "cannot create symlink in $gcRootsDir to $path";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub attrsToSQL {
|
sub attrsToSQL {
|
||||||
my ($attrs, $id) = @_;
|
my ($attrs, $id) = @_;
|
||||||
my @attrs = split / /, $attrs;
|
my @attrs = split / /, $attrs;
|
||||||
|
@ -25,6 +25,8 @@ sub doBuild {
|
|||||||
|
|
||||||
my $errormsg = undef;
|
my $errormsg = undef;
|
||||||
|
|
||||||
|
registerRoot $outPath;
|
||||||
|
|
||||||
if (!isValidPath($outPath)) {
|
if (!isValidPath($outPath)) {
|
||||||
$isCachedBuild = 0;
|
$isCachedBuild = 0;
|
||||||
|
|
||||||
|
@ -248,6 +248,9 @@ sub checkJob {
|
|||||||
, sha256hash => $input->{sha256hash}
|
, sha256hash => $input->{sha256hash}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# !!! this should really by done by nix-instantiate to prevent a GC race.
|
||||||
|
registerRoot $drvPath;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,25 +9,12 @@ use POSIX qw(strftime);
|
|||||||
|
|
||||||
my $db = openHydraDB;
|
my $db = openHydraDB;
|
||||||
|
|
||||||
die unless defined $ENV{LOGNAME};
|
|
||||||
my $gcRootsDir = "/nix/var/nix/gcroots/per-user/$ENV{LOGNAME}/hydra-roots";
|
|
||||||
|
|
||||||
|
|
||||||
my %roots;
|
my %roots;
|
||||||
|
|
||||||
sub registerRoot {
|
sub registerRoot {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
#print "$path\n";
|
Hydra::Helper::Nix::registerRoot($path);
|
||||||
|
|
||||||
mkpath($gcRootsDir) if !-e $gcRootsDir;
|
|
||||||
|
|
||||||
my $link = "$gcRootsDir/" . basename $path;
|
|
||||||
|
|
||||||
if (!-l $link) {
|
|
||||||
symlink($path, $link)
|
|
||||||
or die "cannot create symlink in $gcRootsDir to $path";
|
|
||||||
}
|
|
||||||
|
|
||||||
$roots{$path} = 1;
|
$roots{$path} = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,11 +84,14 @@ my @buildsToKeep = $db->resultset('Builds')->search({finished => 1, keep => 1},
|
|||||||
keepBuild $_ foreach @buildsToKeep;
|
keepBuild $_ foreach @buildsToKeep;
|
||||||
|
|
||||||
|
|
||||||
# For scheduled builds, we register the derivation as a GC root.
|
# For scheduled builds, we register the derivation and the output as a GC root.
|
||||||
print "*** looking for scheduled builds\n";
|
print "*** looking for scheduled builds\n";
|
||||||
foreach my $build ($db->resultset('Builds')->search({finished => 0}, {join => 'schedulingInfo'})) {
|
foreach my $build ($db->resultset('Builds')->search({finished => 0}, {join => 'schedulingInfo'})) {
|
||||||
if (isValidPath($build->drvpath)) {
|
if (isValidPath($build->drvpath)) {
|
||||||
|
print "keeping scheduled build ", $build->id, " (",
|
||||||
|
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
||||||
registerRoot $build->drvpath;
|
registerRoot $build->drvpath;
|
||||||
|
registerRoot $build->outpath;
|
||||||
} else {
|
} else {
|
||||||
print STDERR "warning: derivation ", $build->drvpath, " has disappeared\n";
|
print STDERR "warning: derivation ", $build->drvpath, " has disappeared\n";
|
||||||
}
|
}
|
||||||
@ -109,6 +99,10 @@ foreach my $build ($db->resultset('Builds')->search({finished => 0}, {join => 's
|
|||||||
|
|
||||||
|
|
||||||
# Remove existing roots that are no longer wanted. !!! racy
|
# Remove existing roots that are no longer wanted. !!! racy
|
||||||
|
print "*** removing unneeded GC roots\n";
|
||||||
|
|
||||||
|
my $gcRootsDir = getGCRootsDir;
|
||||||
|
|
||||||
opendir DIR, $gcRootsDir or die;
|
opendir DIR, $gcRootsDir or die;
|
||||||
|
|
||||||
foreach my $link (readdir DIR) {
|
foreach my $link (readdir DIR) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user