Skip to content

Commit

Permalink
[backend] small refactoring of constraints checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Oct 18, 2016
1 parent 7443322 commit 279d465
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
37 changes: 21 additions & 16 deletions src/backend/BSSched/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,25 @@ sub calcrelsynctrigger {
$ctx->{'relsyncmax'} = $relsyncmax;
}

sub prune_packstatus_finished {
my ($gdst, $building) = @_;

my $psf = readstr("$gdst/:packstatus.finished", 1);
return unless $psf;
my %dispatchdetails;
for (split("\n", $psf)) {
my ($code, $rest) = split(' ', $_, 2);
next unless $code eq 'scheduled';
my ($packid, $job, $details) = split('/', $rest, 3);
$dispatchdetails{$packid} = "$_\n" if $job && ($building->{$packid} || '') eq $job;
}
if (%dispatchdetails) {
writestr("$gdst/.:packstatus.finished", "$gdst/.:packstatus.finished", join('', sort values %dispatchdetails));
} else {
unlink("$gdst/:packstatus.finished");
}
}

sub checkpkgs {
my ($ctx) = @_;

Expand Down Expand Up @@ -848,26 +867,12 @@ sub checkpkgs {
'packstatus' => \%packstatus,
'packerror' => \%packerror,
});
# prune packstatus.finished
if (%building) {
my $psf = readstr("$gdst/:packstatus.finished", 1);
if ($psf) {
my %dispatchdetails;
for (split("\n", $psf)) {
my ($code, $rest) = split(' ', $_, 2);
next unless $code eq 'scheduled';
my ($packid, $job, $details) = split('/', $rest, 3);
$dispatchdetails{$packid} = "$_\n" if $job && ($building{$packid} || '') eq $job;
}
if (%dispatchdetails) {
writestr("$gdst/.:packstatus.finished", "$gdst/.:packstatus.finished", join('', sort values %dispatchdetails));
} else {
unlink("$gdst/:packstatus.finished");
}
}
prune_packstatus_finished($gdst, \%building);
} else {
unlink("$gdst/:packstatus.finished");
}

my $schedulerstate;
if (keys %building) {
$schedulerstate = 'building';
Expand Down
2 changes: 1 addition & 1 deletion src/backend/BSXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ our $event = [
'linksrcmd5', # for type=servicedispatch
'projectservicesmd5', # for type=servicedispatch
'oldsrcmd5', # for type=servicedispatch
'details', # for type=dispatchdetails
'details', # for type=dispatchdetails
];

our $events = [
Expand Down
58 changes: 32 additions & 26 deletions src/backend/bs_dispatch
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ my %badhost;
my %newestsrcchange;
my %infocache;
my %constraintscache;
my %scheduleinfo;

my %lastbuild; # last time a job was build in that prpa

Expand Down Expand Up @@ -817,6 +816,36 @@ sub filechecks {
}
}

# check all workers against the job constains so that the
# users get feedback
sub checkconstraints {
my ($info, $arch, $job, $constraints) = @_;

my $details = "";
my @nonidlestates = qw(building away down dead);
for my $nonidlestate (@nonidlestates) {
my $oraresult = 0;
my @workerarr = sort(BSUtil::ls("$workersdir/$nonidlestate"));
for my $workertooracle (@workerarr) {
my $worker = readxml("$workersdir/$nonidlestate/$workertooracle", $BSXML::worker, 1);
next unless $worker;
next if $BSConfig::dispatch_constraint && !$BSConfig::dispatch_constraint->($info, $worker);
$oraresult++ if oracle($worker, $constraints) > 0;
}
if ($oraresult > 0) {
$details .= "$oraresult/" . scalar(@workerarr) . " $nonidlestate ";
}
}
if (!$details) {
$details = "no worker provides the capabilities to comply with the constraints";
}
$details =~ s/\s+$//;
if (!$info->{'scheduleinfo'} || $info->{'scheduleinfo'} ne $details) {
$info->{'scheduleinfo'} = $details;
setdispatchdetails($info, $arch, $job, $details);
}
}

$| = 1;
$SIG{'PIPE'} = 'IGNORE';
BSUtil::restartexit($ARGV[0], 'dispatcher', "$rundir/bs_dispatch");
Expand Down Expand Up @@ -1021,9 +1050,6 @@ while (1) {
for (grep {!$notlocked{$_} && !$locked{$_}} keys (%{$infocache{$arch} || {}})) {
delete $infocache{$arch}->{$_};
}
for (grep {!$notlocked{$_}} keys (%{$scheduleinfo{$arch} || {}})) {
delete $scheduleinfo{$arch}->{$_};
}
# adapt load
for my $job (keys %locked) {
my $jn = $job;
Expand Down Expand Up @@ -1379,29 +1405,9 @@ while (1) {
# we have jobs that could not be assigned and have constraints.
# check if non idle workers could build these job or if there are no
# workers that met the constraints
my @nonidlestates = qw(building away down dead);
if (!$haveassigned && $constraints) {
if ($info->{'allworkercheck'}++ % 5 == 0) {
my $details = "";
foreach my $nonidlestate (@nonidlestates) {
my $oraresult = 0;
my @workerarr = BSUtil::ls("$workersdir/$nonidlestate");
foreach my $workertooracle (@workerarr) {
my $worker = readxml("$workersdir/$nonidlestate/$workertooracle", $BSXML::worker, 1);
$oraresult++ if (oracle($worker,$constraints) == 1);
}
if (scalar(@workerarr) > 0 && $oraresult > 0) {
$details .= "$oraresult/" . scalar(@workerarr) . " $nonidlestate ";
}
}
if ($details eq "") {
$details = "no worker provides the capabilities to comply with the constraints";
}
$details =~ s/\s+$//;
if (!exists $scheduleinfo{$arch}->{$job} || $scheduleinfo{$arch}->{$job} ne $details) {
$scheduleinfo{$arch}->{$job} = $details;
setdispatchdetails($info,$arch,$job,$details);
}
checkconstraints($info, $arch, $job, $constraints);
}
}

Expand Down Expand Up @@ -1451,7 +1457,7 @@ sub setdispatchdetails {
};
BSRPC::rpc($param, undef, "details=$details");
} else {
my $ev = { type => 'dispatchdetails', job => "$job", details => $details };
my $ev = { type => 'dispatchdetails', job => $job, details => $details };
my $evname = "dispatchdetails:$job";
mkdir_p("$eventdir/$arch");
writexml("$eventdir/$arch/.$evname.$$", "$eventdir/$arch/$evname", $ev, $BSXML::event);
Expand Down

0 comments on commit 279d465

Please sign in to comment.