Merge the BuildSchedulingInfo table into the Builds table
This simplifies the code and improves performance since it reduces the number of joins.
This commit is contained in:
@ -398,7 +398,7 @@ sub doBuild {
|
||||
}
|
||||
|
||||
txn_do($db, sub {
|
||||
$build->update({finished => 1, timestamp => time});
|
||||
$build->update({finished => 1, busy => 0, locker => '', logfile => '', timestamp => time});
|
||||
|
||||
my $releaseName = getReleaseName($outPath);
|
||||
|
||||
@ -423,8 +423,6 @@ sub doBuild {
|
||||
if ($buildStatus == 0 || $buildStatus == 6) {
|
||||
addBuildProducts($db, $build);
|
||||
}
|
||||
|
||||
$build->schedulingInfo->delete;
|
||||
});
|
||||
|
||||
sendEmailNotification $build;
|
||||
@ -453,10 +451,10 @@ txn_do($db, sub {
|
||||
$build = $db->resultset('Builds')->find($buildId);
|
||||
die "build $buildId doesn't exist" unless defined $build;
|
||||
die "build $buildId already done" if defined $build->resultInfo;
|
||||
if ($build->schedulingInfo->busy != 0 && $build->schedulingInfo->locker != getppid) {
|
||||
if ($build->busy != 0 && $build->locker != getppid) {
|
||||
die "build $buildId is already being built";
|
||||
}
|
||||
$build->schedulingInfo->update({busy => 1, locker => $$});
|
||||
$build->update({busy => 1, locker => $$});
|
||||
$build->buildsteps->search({busy => 1})->delete_all;
|
||||
$build->buildproducts->delete_all;
|
||||
});
|
||||
@ -472,6 +470,6 @@ eval {
|
||||
if ($@) {
|
||||
warn $@;
|
||||
txn_do($db, sub {
|
||||
$build->schedulingInfo->update({busy => 0, locker => $$});
|
||||
$build->update({busy => 0, locker => $$});
|
||||
});
|
||||
}
|
||||
|
@ -20,10 +20,9 @@ STDOUT->autoflush();
|
||||
sub unlockDeadBuilds {
|
||||
# Unlock builds whose building process has died.
|
||||
txn_do($db, sub {
|
||||
my @builds = $db->resultset('Builds')->search(
|
||||
{finished => 0, busy => 1}, {join => 'schedulingInfo'});
|
||||
my @builds = $db->resultset('Builds')->search({finished => 0, busy => 1});
|
||||
foreach my $build (@builds) {
|
||||
my $pid = $build->schedulingInfo->locker;
|
||||
my $pid = $build->locker;
|
||||
my $unlock = 0;
|
||||
if ($pid == $$) {
|
||||
# Work around sqlite locking timeouts: if the child
|
||||
@ -32,7 +31,7 @@ sub unlockDeadBuilds {
|
||||
# So if after a minute it hasn't been updated,
|
||||
# unlock the build. !!! need a better fix for those
|
||||
# locking timeouts.
|
||||
if ($build->schedulingInfo->starttime + 60 < time) {
|
||||
if ($build->starttime + 60 < time) {
|
||||
$unlock = 1;
|
||||
}
|
||||
} elsif (kill(0, $pid) != 1) { # see if we can signal the process
|
||||
@ -40,9 +39,9 @@ sub unlockDeadBuilds {
|
||||
}
|
||||
if ($unlock) {
|
||||
print "build ", $build->id, " pid $pid died, unlocking\n";
|
||||
$build->schedulingInfo->busy(0);
|
||||
$build->schedulingInfo->locker("");
|
||||
$build->schedulingInfo->update;
|
||||
$build->busy(0);
|
||||
$build->locker("");
|
||||
$build->update;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -64,7 +63,7 @@ sub findBuildDependencyInQueue {
|
||||
|
||||
($depBuild) = $db->resultset('Builds')->search(
|
||||
{ drvpath => [ @drvs ], finished => 0, busy => 0, enabled => 1, disabled => 0 },
|
||||
{ join => ['schedulingInfo', 'project'], rows => 1 } ) ;
|
||||
{ join => ['project'], rows => 1 } ) ;
|
||||
return $depBuild;
|
||||
}
|
||||
|
||||
@ -79,7 +78,7 @@ sub checkBuilds {
|
||||
# Get the system types for the runnable builds.
|
||||
my @systemTypes = $db->resultset('Builds')->search(
|
||||
{ finished => 0, busy => 0, enabled => 1, disabled => 0 },
|
||||
{ join => ['schedulingInfo', 'project'], select => ['system'], as => ['system'], distinct => 1 });
|
||||
{ join => ['project'], select => ['system'], as => ['system'], distinct => 1 });
|
||||
|
||||
# For each system type, select up to the maximum number of
|
||||
# concurrent build for that system type. Choose the highest
|
||||
@ -88,8 +87,7 @@ sub checkBuilds {
|
||||
# How many builds are already currently executing for this
|
||||
# system type?
|
||||
my $nrActive = $db->resultset('Builds')->search(
|
||||
{finished => 0, busy => 1, system => $system->system},
|
||||
{join => 'schedulingInfo'})->count;
|
||||
{finished => 0, busy => 1, system => $system->system})->count;
|
||||
|
||||
# How many extra builds can we start?
|
||||
(my $systemTypeInfo) = $db->resultset('SystemTypes')->search({system => $system->system});
|
||||
@ -100,7 +98,7 @@ sub checkBuilds {
|
||||
# Select the highest-priority builds to start.
|
||||
my @builds = $extraAllowed == 0 ? () : $db->resultset('Builds')->search(
|
||||
{ finished => 0, busy => 0, system => $system->system, enabled => 1, disabled => 0 },
|
||||
{ join => ['schedulingInfo', 'project'], order_by => ["priority DESC", "timestamp"],
|
||||
{ join => ['project'], order_by => ["priority DESC", "timestamp"],
|
||||
rows => $extraAllowed });
|
||||
|
||||
print "system type `", $system->system,
|
||||
@ -114,11 +112,11 @@ sub checkBuilds {
|
||||
my $logfile = getcwd . "/logs/" . $build->id;
|
||||
mkdir(dirname $logfile);
|
||||
unlink($logfile);
|
||||
$build->schedulingInfo->busy(1);
|
||||
$build->schedulingInfo->locker($$);
|
||||
$build->schedulingInfo->logfile($logfile);
|
||||
$build->schedulingInfo->starttime(time);
|
||||
$build->schedulingInfo->update;
|
||||
$build->busy(1);
|
||||
$build->locker($$);
|
||||
$build->logfile($logfile);
|
||||
$build->starttime(time);
|
||||
$build->update;
|
||||
push @buildsStarted, $build;
|
||||
}
|
||||
}
|
||||
@ -130,7 +128,7 @@ sub checkBuilds {
|
||||
my $id = $build->id;
|
||||
print "starting build $id (", $build->project->name, ":", $build->jobset->name, ':', $build->job->name, ") on ", $build->system, "\n";
|
||||
eval {
|
||||
my $logfile = $build->schedulingInfo->logfile;
|
||||
my $logfile = $build->logfile;
|
||||
my $child = fork();
|
||||
die unless defined $child;
|
||||
if ($child == 0) {
|
||||
@ -147,9 +145,9 @@ sub checkBuilds {
|
||||
if ($@) {
|
||||
warn $@;
|
||||
txn_do($db, sub {
|
||||
$build->schedulingInfo->busy(0);
|
||||
$build->schedulingInfo->locker($$);
|
||||
$build->schedulingInfo->update;
|
||||
$build->busy(0);
|
||||
$build->locker($$);
|
||||
$build->update;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ keepBuild $_ foreach @buildsToKeep;
|
||||
|
||||
# For scheduled builds, we register the derivation as a GC root.
|
||||
print STDERR "*** 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})) {
|
||||
if (isValidPath($build->drvpath)) {
|
||||
print STDERR "keeping scheduled build ", $build->id, " (",
|
||||
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
||||
|
Reference in New Issue
Block a user