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

[Xen-devel] [OSSTEST PATCH 16/25] sg-report-host-history: Break out computeflightsrange



To do database locking coherently, it will be convenient to have this
in a function.

No functional change.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 sg-report-host-history |   65 +++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 31 deletions(-)

diff --git a/sg-report-host-history b/sg-report-host-history
index 14f8458..c56ed71 100755
--- a/sg-report-host-history
+++ b/sg-report-host-history
@@ -58,42 +58,44 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
 
 @ARGV or die $!;
 
-$dbh_tests->begin_work;
-
-if (!$flightlimit) {
-    my $flagscond =
-       '('.join(' OR ', map { "f.hostflag = 'blessed-$_'" } @blessings).')';
-    my $nhostsq = db_prepare(<<END);
-        SELECT count(*)
-         FROM resources r
-        WHERE restype='host'
-          AND EXISTS (SELECT 1
-                        FROM hostflags f
-                       WHERE f.hostname=r.resname
-                         AND $flagscond)
+our $flightcond;
+
+sub computeflightsrange () {
+    if (!$flightlimit) {
+       my $flagscond =
+           '('.join(' OR ', map { "f.hostflag = 'blessed-$_'" } 
@blessings).')';
+       my $nhostsq = db_prepare(<<END);
+           SELECT count(*)
+             FROM resources r
+            WHERE restype='host'
+              AND EXISTS (SELECT 1
+                            FROM hostflags f
+                           WHERE f.hostname=r.resname
+                             AND $flagscond)
 END
-    $nhostsq->execute();
-    my ($nhosts) = $nhostsq->fetchrow_array();
-    print DEBUG "COUNTED $nhosts hosts\n";
-    $flightlimit = $nhosts * $limit * 2;
-}
+        $nhostsq->execute();
+       my ($nhosts) = $nhostsq->fetchrow_array();
+       print DEBUG "COUNTED $nhosts hosts\n";
+       $flightlimit = $nhosts * $limit * 2;
+    }
 
-my $minflightsq = db_prepare(<<END);
-    SELECT flight
-      FROM (
+    my $minflightsq = db_prepare(<<END);
        SELECT flight
-         FROM flights
-        ORDER BY flight DESC
-        LIMIT $flightlimit
-      ) f
-      ORDER BY flight ASC
-      LIMIT 1
+         FROM (
+           SELECT flight
+             FROM flights
+            ORDER BY flight DESC
+            LIMIT $flightlimit
+         ) f
+         ORDER BY flight ASC
+         LIMIT 1
 END
-$minflightsq->execute();
-my ($minflight) = $minflightsq->fetchrow_array();
-$minflight //= 0;
+    $minflightsq->execute();
+    my ($minflight) = $minflightsq->fetchrow_array();
+    $minflight //= 0;
 
-our $flightcond = "(flight > $minflight)";
+    $flightcond = "(flight > $minflight)";
+}
 
 $dbh_tests->do("SET LOCAL enable_seqscan=false");
 # Otherwise the PostgreSQL query planner likes to do a complete scan
@@ -243,4 +245,5 @@ sub reporthost ($) {
     rename "$html_file.new", "$html_file" or die "$html_file $!";
 }
 
+computeflightsrange();
 reporthost $_ foreach @ARGV;
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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