diff mbox

[OSSTEST,8/9] mg-allocate: Better error handling when no candidates

Message ID 1450371968-27997-8-git-send-email-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Jackson Dec. 17, 2015, 5:06 p.m. UTC
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 <Ian.Jackson@eu.citrix.com>
---
 mg-allocate |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

Ian Campbell Dec. 17, 2015, 5:33 p.m. UTC | #1
On Thu, 2015-12-17 at 17:06 +0000, Ian Jackson wrote:
> 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 <Ian.Jackson@eu.citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>
diff mbox

Patch

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);
 }