Skip to content

Commit

Permalink
Merge pull request #2237 from lethliel/mod_dispatcher
Browse files Browse the repository at this point in the history
[backend] identify non-idle workers for constraints
  • Loading branch information
mlschroe committed Oct 18, 2016
2 parents b5dea42 + c3a3603 commit 7443322
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 5 deletions.
21 changes: 20 additions & 1 deletion src/backend/BSSched/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,26 @@ sub checkpkgs {
'packstatus' => \%packstatus,
'packerror' => \%packerror,
});
unlink("$gdst/:packstatus.finished");
# 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");
}
}
} else {
unlink("$gdst/:packstatus.finished");
}
my $schedulerstate;
if (keys %building) {
$schedulerstate = 'building';
Expand Down
16 changes: 16 additions & 0 deletions src/backend/BSSched/EventHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ our %event_handlers = (
'configuration' => \&BSSched::EventHandler::event_configuration,
'suspendproject' => \&BSSched::EventHandler::event_suspendproject,
'memstats' => \&BSSched::EventHandler::event_memstats,
'dispatchdetails' => \&BSSched::EventHandler::event_dispatchdetails,
);

=head1 NAME
Expand Down Expand Up @@ -612,4 +613,19 @@ sub event_memstats {
%$gctx = %gctx;
}

sub event_dispatchdetails {
my ($ectx, $ev) = @_;
my $gctx = $ectx->{'gctx'};
my $myarch = $gctx->{'arch'};
my $myjobsdir = $gctx->{'myjobsdir'};
my $reporoot = $gctx->{'reporoot'};
my $info = readxml("$myjobsdir/$ev->{'job'}", $BSXML::buildinfo, 1);
return unless $info;
return if -e "$myjobsdir/$ev->{'job'}:status";
my $job = $ev->{'job'};
$job =~ s/.*\///;
my $gdst = "$reporoot/$info->{'project'}/$info->{'repository'}/$myarch";
BSUtil::appendstr("$gdst/:packstatus.finished", "scheduled $info->{'package'}/$job/$ev->{'details'}\n");
}

1;
1 change: 1 addition & 0 deletions src/backend/BSXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ our $event = [
'linksrcmd5', # for type=servicedispatch
'projectservicesmd5', # for type=servicedispatch
'oldsrcmd5', # for type=servicedispatch
'details', # for type=dispatchdetails
];

our $events = [
Expand Down
50 changes: 50 additions & 0 deletions src/backend/bs_dispatch
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ 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 @@ -1020,6 +1021,9 @@ 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 @@ -1372,6 +1376,35 @@ while (1) {
$haveassigned = 1;
last;
}
# 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);
}
}
}

# Tricky, still increase load so that we don't assign
# too many non-powerjobs. But only do that once for each powerjob.
if (!$haveassigned && $powerjobs{$job} && !$extraload{"$arch/$job"}) {
Expand Down Expand Up @@ -1408,3 +1441,20 @@ while (1) {
}
filechecks();
}

sub setdispatchdetails {
my ($info, $arch, $job, $details) = @_;
if ($info->{'masterdispatched'}) {
my $param = {
'uri' => "$info->{'reposerver'}/$arch/$job",
'request' => 'POST',
};
BSRPC::rpc($param, undef, "details=$details");
} else {
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);
BSUtil::ping("$eventdir/$arch/.ping");
}
}
29 changes: 25 additions & 4 deletions src/backend/bs_repserver
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,16 @@ sub readpackstatus {
if ($psf) {
for (split("\n", $psf)) {
my ($code, $packid) = split(' ', $_, 2);
next unless ($ps->{'packstatus'}->{$packid} || '') eq 'scheduled';
$ps->{'packstatus'}->{$packid} = 'finished';
$ps->{'packerror'}->{$packid} = $code;
if ($code eq 'scheduled') {
my ($job, $details);
($packid, $job, $details) = split('/', $packid, 3);
next unless ($ps->{'packstatus'}->{$packid} || '') eq 'scheduled';
$ps->{'packerror'}->{$packid} = $details;
} else {
next unless ($ps->{'packstatus'}->{$packid} || '') eq 'scheduled';
$ps->{'packstatus'}->{$packid} = 'finished';
$ps->{'packerror'}->{$packid} = $code;
}
}
}
return $ps;
Expand Down Expand Up @@ -3442,6 +3449,19 @@ sub idleworkerjob {
return $BSStdServer::return_ok;
}

sub setdispatchdetails {
my ($cgi, $arch, $job) = @_;
my $info = readxml("$jobsdir/$arch/$job", $BSXML::buildinfo, 1);
if ($info) {
my $ev = { type => 'dispatchdetails', job => "$arch/$job", details => $cgi->{'details'}};
my $evname = "dispatchdetails:$job";
mkdir_p("$eventdir/$arch");
writexml("$eventdir/$arch/.$evname.$$", "$eventdir/$arch/$evname", $ev, $BSXML::event);
BSUtil::ping("$eventdir/$arch/.ping");
}
return $BSStdServer::return_ok;
}

sub putconfiguration {
my ($cgi) = @_;
mkdir_p($uploaddir);
Expand Down Expand Up @@ -3485,14 +3505,14 @@ my $dispatches = [
'!- GET:' => undef,
'!- HEAD:' => undef,

'POST:/build/$project cmd=move oproject:project' => \&moveproject,
'POST:/build/$project/$repository/$arch/_repository match:' => \&postrepo,
'/build/$project/$repository/$arch package* view:?' => \&getpackagelist_build,
'/build/$project/$repository/$arch/_builddepinfo package* view:?' => \&getbuilddepinfo,
'/build/$project/$repository/$arch/_jobhistory package* code:* limit:num?' => \&getjobhistory,
'POST:/build/$project/$repository/$arch/_relsync' => \&postrelsync,
'/build/$project/$repository/$arch/_relsync' => \&getrelsync,
'POST:/build/$project/$repository/$arch/$package cmd=copy oproject:project? opackage:package? orepository:repository? setupdateinfoid:? resign:bool? setrelease:?' => \&copybuild,
'POST:/build/$project cmd=move oproject:project' => \&moveproject,
'POST:/build/$project/$repository/$arch/$package' => \&uploadbuild,
'!worker,rw /build/$project/$repository/$arch/$package:package_repository view:? binary:filename* nometa:bool? noajax:bool? nosource:bool? noimport:bool? withmd5:bool?' => \&getbinarylist,
'POST:/build/$project/$repository/$arch/$package_repository/_buildinfo add:* internal:bool? debug:bool? deps:bool?' => \&getbuildinfo_post,
Expand Down Expand Up @@ -3540,6 +3560,7 @@ my $dispatches = [
'/jobs/$arch' => \&listjobs,
'PUT:/jobs/$arch/$job' => \&addjob,
'POST:/jobs/$arch/$job cmd=idleworker workerid jobid?' => \&idleworkerjob,
'POST:/jobs/$arch/$job cmd=setdispatchdetails details:' => \&setdispatchdetails,
'DELETE:/jobs/$arch/$job' => \&deljob,
'/jobs/$arch/$job view:?' => \&getjob,

Expand Down

0 comments on commit 7443322

Please sign in to comment.