From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [OSSTEST PATCH 8/9] mg-allocate: Better error handling when no candidates Date: Thu, 17 Dec 2015 17:06:07 +0000 Message-ID: <1450371968-27997-8-git-send-email-ian.jackson@eu.citrix.com> References: <1450371968-27997-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a9c0T-0005u7-Q7 for xen-devel@lists.xenproject.org; Thu, 17 Dec 2015 17:06:21 +0000 In-Reply-To: <1450371968-27997-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org Spot when our db search revealed no candidates for the resources to allocate, and: - when doing an immediate allocation, call it an error - when doing a planned allocation, cause it to prevent allocation on this iteration, and print a suitably unreassuring message Previously it would simply say `nothing available'. Implement this as follows: - Report lack of candidates as $ok=-1 from alloc_1rescand - In alloc_1res, return this -1 as with any non-zero $ok - Handle the new $ok at all the call sites, in particular - In plan(), rename `allok' to `worstok' and have it be the worst relevant $ok value. If $ok gives -1, return undef, rather than a booking list, to the allocator core. Signed-off-by: Ian Jackson --- mg-allocate | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mg-allocate b/mg-allocate index 4c32fa8..54a7af3 100755 --- a/mg-allocate +++ b/mg-allocate @@ -211,6 +211,9 @@ END $got_shareix= $candrow->{shareix}; $ok=1; last; } + if (!$resq->rows) { + return (-1,undef); + } return ($ok, { Allocate => $allocate, Shareix => $got_shareix, Info => "$resname ($restype/$resname/$got_shareix)" @@ -248,6 +251,8 @@ sub execute () { if (!$ok) { logm("nothing available for $res, sorry"); $allok=0; + } elsif ($ok < 0) { + die "*** no candidates for $res! ***\n"; } else { logm("processed $res (shareix=$got->{Shareix})"); push @got, $got; @@ -314,17 +319,19 @@ sub plan () { logm("best at $planned->{Start} is ".showposs(\@reqlist)); die unless $planned; - my $allok=0; + my $worstok=0; if ($mayalloc && !$planned->{Start}) { - $allok=1; + $worstok=1; alloc_prep(); foreach my $req (@reqlist) { my ($ok, $got) = alloc_1res($req->{Ident}); + $worstok = $ok if $ok < $worstok; if (!$ok) { logm("failed to allocate $req->{Ident}!"); - $allok=0; + } elsif ($ok < 0) { + logm("*** no candidates for $req->{Ident}! ***"); } else { $req->{GotShareix}= $got->{Shareix}; push @got, $got; @@ -332,9 +339,12 @@ sub plan () { } } - if ($allok) { + if ($worstok > 0) { logm("allocated, notifying..."); - } else { + } elsif ($worstok < 0) { + logm("*** problems, maybe missing resources? ***"); + return (0, undef); + } else { logm("booking..."); } @@ -346,7 +356,7 @@ sub plan () { Start => $planned->{Start}, End => $planned->{Start} + $duration, }; - if ($allok) { + if ($worstok > 0) { $book->{Allocated}= { Task => $tid, Shareix => $req->{GotShareix}, @@ -355,7 +365,7 @@ sub plan () { push @bookings, $book; } - return ($allok, { Bookings => \@bookings }); + return ($worstok, { Bookings => \@bookings }); }); loggot(@got); } -- 1.7.10.4