[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OSSTEST PATCH 52/82] host allocation: Group jobs by their reuse parameters



From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>

This promotes reuse by arranging that jobs that can reuse a host get
to run consecutively.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 Osstest/JobDB/Executive.pm  | 47 +++++++++++++++++++++++++++++++++++++
 Osstest/JobDB/Standalone.pm |  2 ++
 ts-host-reuse               |  1 +
 ts-hosts-allocate-Executive |  4 ++++
 4 files changed, 54 insertions(+)

diff --git a/Osstest/JobDB/Executive.pm b/Osstest/JobDB/Executive.pm
index 30629572..8c235d45 100644
--- a/Osstest/JobDB/Executive.pm
+++ b/Osstest/JobDB/Executive.pm
@@ -389,6 +389,53 @@ END
     }
 }
 
+sub jobdb_set_hosts_infraprioritygroup ($$$$;$) { # method
+    my ($mo, $flight, $job, $group_key, $rref) = @_;
+    # Sets the runvar hosts_infraprioritygroup in $flight,$job
+    # The runvar values are NUM:GROUPKEY
+    # such that each GROUPKEY always has the same NUM, within the flight
+    # $rref is \%r (for use within a ts-*) or undef
+
+    my $vn = 'hosts_infraprioritygroup';
+
+    my $queryq = $dbh_tests->prepare(<<END);
+        SELECT job, val,
+               (job = ?) AS thisjob
+          FROM runvars
+         WHERE flight=?
+           AND name=?
+      ORDER BY thisjob DESC
+END
+    my $insertq = $dbh_tests->prepare(<<END);
+        INSERT INTO runvars (flight,job, name,val, synth)
+                     VALUES (?,     ?,   ?,   ?,   't')
+END
+
+    my $resulting;
+    db_retry($dbh_tests,[],sub {
+       my $use = 1;
+       $resulting = undef;
+        $queryq->execute($job, $flight, $vn);
+       while (my ($tjob, $tval, $thisjob) = $queryq->fetchrow_array()) {
+           if ($thisjob) {
+               logm("$vn: job is already in group $tval");
+               return;
+           }
+           $tval =~ m/^(\d+)\:/ or die "$flight $job $tval ?";
+           if ($' eq $group_key) {
+               $use = $1;
+               last;
+           } elsif ($1 >= $use) {
+               $use = $1 + 1;
+           }
+       }
+       $resulting = "$use:$group_key";
+       logm("$vn: inserting job into group $resulting");
+       $insertq->execute($flight,$job,$vn, $resulting);
+    });
+    $rref->{$vn} = $resulting if $rref && defined $resulting;
+}
+
 sub jobdb_flight_started_for_log_capture ($$) { #method
     my ($mo, $flight) = @_;
     my $started= $dbh_tests->selectrow_array(<<END);
diff --git a/Osstest/JobDB/Standalone.pm b/Osstest/JobDB/Standalone.pm
index 4f320ccf..1db4dc78 100644
--- a/Osstest/JobDB/Standalone.pm
+++ b/Osstest/JobDB/Standalone.pm
@@ -118,6 +118,8 @@ sub jobdb_resource_shared_mark_ready { } #method
 
 sub jobdb_check_other_job { } #method
 
+sub jobdb_set_hosts_infraprioritygroup { } # method
+
 sub jobdb_flight_started_for_log_capture ($$) { #method
     my ($mo, $flight) = @_;
     return time - 60*60; # just the most recent serial log then,
diff --git a/ts-host-reuse b/ts-host-reuse
index 5bdb07d1..29abe987 100755
--- a/ts-host-reuse
+++ b/ts-host-reuse
@@ -141,6 +141,7 @@ sub act_prealloc () {
     compute_test_sharetype();
     $ho = selecthost($whhost, undef, 1);
     set_runtime_hostflag($ho->{Ident}, "reuse-$sharetype");
+    $mjobdb->jobdb_set_hosts_infraprioritygroup($flight, $job, $sharetype, 
\%r);
 }
 
 sub act_start_test () {
diff --git a/ts-hosts-allocate-Executive b/ts-hosts-allocate-Executive
index fc107c08..a50f8bf3 100755
--- a/ts-hosts-allocate-Executive
+++ b/ts-hosts-allocate-Executive
@@ -733,9 +733,13 @@ sub alloc_hosts () {
         ? -10000
         : -10 * @hids;
 
+    my $infrapriority =
+       ($r{hosts_infraprioritygroup} // '') =~ m/^(\d+):/ ? $1 : undef;
+
     my $ok = alloc_resources(WaitStart =>
                     ($ENV{OSSTEST_RESOURCE_WAITSTART} || $fi->{started}),
                     WaitStartAdjust => $waitstartadjust,
+                    InfraPriority => $infrapriority,
                    DebugFh => \*DEBUG,
                     \&attempt_allocation);
 
-- 
2.20.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.