xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [OSSTEST PATCH 5/6] flight preservation: Honour flight allocation during expiry
Date: Tue, 4 Oct 2016 13:26:33 +0100	[thread overview]
Message-ID: <1475583994-30203-5-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1475583994-30203-1-git-send-email-ian.jackson@eu.citrix.com>

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@eu.citrix.com>
---
 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@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-10-04 12:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04 12:26 [OSSTEST PATCH 1/6] cr-ensure-disk-space: Do not take out the lock in dry run mode Ian Jackson
2016-10-04 12:26 ` [OSSTEST PATCH 2/6] cr-ensure-disk-space: -F option Ian Jackson
2016-10-04 12:26 ` [OSSTEST PATCH 3/6] cr-ensure-disk-space: Dry run produces better `die' message Ian Jackson
2016-10-04 12:26 ` [OSSTEST PATCH 4/6] mg-allocate: Tiny refactoring Ian Jackson
2016-10-04 12:26 ` Ian Jackson [this message]
2016-10-04 12:26 ` [OSSTEST PATCH 6/6] flight preservation: Provide a way to allocate flights Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475583994-30203-5-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).