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

[Xen-devel] [OSSTEST PATCH 5/6] flight preservation: Honour flight allocation during expiry



Look in the resources and tasks table for a resources table entry
corresponding to each flight, owned by a live task.  Such flights are
not deleted.

Specifically:
 * At the start, we get a list of all the preserved flights, and
   also print the information to stdout.
 * Whenever we compare flight numbers for inequality (as a proxy
   for flight age), we first compare where the flights are allocated.
   (When there are references, the effect is that an allocated
   referring flight counts as very late, so $latestref will contain it.)
 * Before actually deleting the selected flight we check it's not
   allocated.  (Strictly, we check it's "latest" reference is not
   allocated.)

Currently there is nothing which creates such resources table entries
so there is no overall functional change.  Also, as a result, the doc
reads rather oddly.  This will be fixed in the next patch.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 README.planner       | 11 +++++++++++
 cr-ensure-disk-space | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/README.planner b/README.planner
index bb18432..9d35b40 100644
--- a/README.planner
+++ b/README.planner
@@ -199,6 +199,17 @@ that shared systems get regrooved occasionally even if 
nothing decides
 to unshare them.
 
 
+Flights
+-------
+
+Flight logs and build artefacts are normally expired based on their
+start time, or the start time of the most recent flight which refers
+to them.
+
+Flights can be protected (preserved) by allocating them somehow:
+Flights are represented by restype='share-flight' entries in the
+resources table.
+
 
 DETAILED PROTOCOL NOTES
 =======================
diff --git a/cr-ensure-disk-space b/cr-ensure-disk-space
index 83372ca..7846580 100755
--- a/cr-ensure-disk-space
+++ b/cr-ensure-disk-space
@@ -100,9 +100,45 @@ my $refq= db_prepare(<<END);
        AND flight >= ?
 END
 
+my $allocqtxt = <<END;
+    SELECT resname AS flight,
+           shareix,
+           (tasks. taskid  ||  ' ' ||
+            tasks.type     ||  ' ' ||
+            tasks.refkey   || ': ' ||
+   COALESCE(tasks.username,'[no username]') ||  ' ' ||
+   COALESCE(tasks.comment, '[no comment]')
+           ) AS info
+      FROM resources
+      JOIN tasks
+        ON owntaskid = taskid
+     WHERE live
+       AND owntaskid != (SELECT taskid FROM tasks
+                         WHERE type='magic' AND refkey='allocatable')
+       AND restype='share-flight'
+END
+
+my $allocq = db_prepare(<<END);
+$allocqtxt
+       AND resname ::int >= ?
+END
+
+my $allocchkq = db_prepare(<<END);
+$allocqtxt
+       AND resname = ?
+     LIMIT 1
+END
+
 our @flights;
+our %allocd;
 our %latestref;
 
+sub flight_num_cmp ($$) {
+    my ($x,$y) = @_;
+    !!$allocd{$x} <=> !!$allocd{$y} or
+            $x    <=>           $y;
+}
+
 sub iteration_proceed () {
     if (!@flights) {
        %latestref = ();
@@ -119,20 +155,27 @@ sub iteration_proceed () {
 
        print DEBUG "MINFLIGHT $minflight\n";
 
+       %allocd = ();
+       $allocq->execute($minflight);
+       while (my $ar= $allocq->fetchrow_hashref) {
+           print DEBUG "preserving allocated $ar->{flight}: $ar->{info}\n";
+           push @{ $allocd{ $ar->{flight} } }, $ar->{info};
+       }
+
        $refq->execute($minflight);
        while (my $rr= $refq->fetchrow_hashref) {
            my $testflight = $rr->{flight};
            next unless $rr->{val} =~ m/^(\d+)\./;
            my $buildflight = $1;
            next unless exists $latestref{$buildflight};
-           if ($testflight > $latestref{$buildflight}) {
+           if (flight_num_cmp($testflight, $latestref{$buildflight}) > 0) {
                print DEBUG "REF $buildflight <- $testflight\n";
                $latestref{$buildflight} = $testflight;
            }
        }
 
        @flights =
-           sort { $latestref{$b} <=> $latestref{$a} }
+           sort { flight_num_cmp($latestref{$b}, $latestref{$a}) }
            keys %latestref;
         printf "(%d flights) ", scalar @flights;
         die unless @flights;
@@ -151,6 +194,11 @@ sub iteration_proceed () {
 
     die "age $age" if $age < logcfg('MinExpireAge');
 
+    $allocchkq->execute($latestref);
+    my $arow= $allocchkq->fetchrow_hashref();
+    $allocchkq->finish();
+    die "alloc $arow->{info} !" if $arow;
+
     printf "...";
 
     die "dry run" if $dryrun;
-- 
2.1.4


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

 


Rackspace

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