xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <iwj@xenproject.org>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [OSSTEST PATCH 68/82] host lifecycle: Prevent referential integrity violation
Date: Wed,  7 Oct 2020 19:00:10 +0100	[thread overview]
Message-ID: <20201007180024.7932-69-iwj@xenproject.org> (raw)
In-Reply-To: <20201007180024.7932-1-iwj@xenproject.org>

From: Ian Jackson <ian.jackson@eu.citrix.com>

We can't use normal constraints for either of these, sadly.

We can make the constraints into a single query which says "OK".

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 Osstest/JobDB/Executive.pm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/Osstest/JobDB/Executive.pm b/Osstest/JobDB/Executive.pm
index 3a8308e9..f69ce277 100644
--- a/Osstest/JobDB/Executive.pm
+++ b/Osstest/JobDB/Executive.pm
@@ -553,6 +553,28 @@ END
                ON h.taskid = t.taskid
             WHERE h.hostname = ?
          ORDER BY h.lcseq;
+END
+    # We simulate two foreign key constraints which can't be in the
+    # db schema, by checking the values we are going to insert.
+    #
+    # For "resources" we would need a foreign key constraint
+    # with a literal value as part of the foreign key, which is
+    # not supported until PostgreSQL 13.
+    #
+    # For "tasks" we only want to apply the constraint on inserts into
+    # "host_lifecycle" - in particular, we want to allow delet6ions
+    # from "tasks" to render the taskid foreign key unresolvable.
+    # This could be done with a trigger, but since here is the only
+    # place we do insertions into host_lifecycle, this seems easier.
+    my $constraintsq = $dbh_tests->prepare(<<END);
+           SELECT * FROM
+	     (SELECT 1 AS ok
+	        FROM resources where restype='host' and resname=?) 
+              hostname_ok
+             NATURAL JOIN
+             (SELECT 1 AS ok
+                FROM tasks where taskid=? AND live)
+              taskid_ok;
 END
     my $insertq = $dbh_tests->prepare(<<END);
         INSERT INTO host_lifecycle
@@ -632,6 +654,9 @@ END
 		push @lifecycle, "$omarks$otj:$o->{stepno}$osuffix";
 	    }
 	}
+	$constraintsq->execute($hostname, $ttaskid);
+	$constraintsq->fetchrow_array() or confess "$hostname ?";
+
 	if (defined $flight) {
 	    $insertq->execute($hostname, $ttaskid,
 			      $flight, $job,
-- 
2.20.1



  parent reply	other threads:[~2020-10-07 18:27 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 17:59 [OSSTEST PATCH 00/82] Reuse test hosts Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 01/82] ms-queuedaemon: Update for newer Tcl's socket channel ids Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 02/82] Executive.pm planner: fix typo Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 03/82] README.planner: Document magic job hostflags Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 04/82] sg-run-job: Minor whitespace (formatting) changes Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 05/82] sg-run-job: Improve some internal API docs Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 06/82] show_abs_time: Represent undef $timet as <undef> Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 07/82] ts-hosts-allocate-Executive: Add a comment about a warning Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 08/82] host reuse: ms-planner: Bring some variables forward Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 09/82] host reuse: ms-planner: Do not show reuse as shared in the plan Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 10/82] hsot reuse: ms-planner: Abbreviate reporting of test shares Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 11/82] cr-publish-flight-logs: Fix abs_time calls Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 12/82] target setup refactoring: Move target_kernkind_check Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 13/82] target setup refactoring: Move target_kernkind_console_inittab Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 14/82] target setup refactoring: Merge target_kernkind_* Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 15/82] target setup refactoring: Add a doc comment Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 16/82] abolish "kernkind"; desupport non-pvops kernels Ian Jackson
2020-10-13  9:29   ` Wei Liu
2020-10-07 17:59 ` [OSSTEST PATCH 17/82] Debian: osstest-erase-other-disks: Slightly guard against races Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 18/82] host allocation: Remove some unnecessary definedness tests Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 19/82] host allocation: Executive: Honour $xparams{InfraPriority} Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 20/82] ts-hosts-allocate-Executive: Fix handling of failed preps for same sharing Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 21/82] sg-run-job: support +! for *only* adding things to TESTID Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 22/82] sg-run-job: Use +! in per-host-ts implementation Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 23/82] db_retry: Make the sleeps random and increasing Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 24/82] host allocation: *_shared_mark_ready: Allow other states Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 25/82] host allocation: *_shared_mark_ready: Make $sharetype check optional Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 26/82] host allocation: selecthost: allow sort-of-selection of prospective hosts Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 27/82] host allocation: *_shared_mark_ready: allow alternative $oldtypes Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 28/82] host allocation: Support new reuse-* magic hostflag Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 29/82] host allocation: *_shared_mark_ready: Only prod when $newstate is ready Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 30/82] plan_search: Break out $share_compat_ok Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 31/82] plan_search: Improve debugging of $share_compat_ok->() Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 32/82] plan_search: Use plan's Wear information rather than tracking it ourselves Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 33/82] plan search: Move $share_compat_ok further up the file Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 34/82] plan_search: Track last sharing state to determine $share_reuse Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 35/82] resource reporting: Print username when listing "rogue tasks" Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 36/82] resource reporting, nfc: Break out report_rogue_task_description Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 37/82] ts-hosts-allocate-Executive: Better message for hosts abandoned mid-test Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 38/82] ts-host-reuse: New script, to do reuse state changes Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 39/82] ts-host-reuse: tolerate unremoveable lv Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 40/82] ts-host-reuse: Do not depend on bios Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 41/82] ts-host-reuse: Add some missing runvars to the host sharing control Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 42/82] host allocation: selecthost(): Support @IDENT for reuse Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 43/82] ts-hosts-allocate-Executive print sharing info in debug output Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 44/82] sg-run-job: New @ iffail tag for prep tasks Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 45/82] sg-run-job: Detect improper use of @ iffail with run-ts Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 46/82] shared/reuse: Use @ for ts-xen-build-prep Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 47/82] shared/reuse: Use @ for ts-host-install Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 48/82] shared/reuse: Use @ for freebsd host prep Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 49/82] host reuse: sg-run-job: per-host prep: Use @ for per-host-ts Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 50/82] shared/reuse: Rely on @ for ts-host-ping-check Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 51/82] host reuse: Reuse test hosts within a flight Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 52/82] host allocation: Group jobs by their reuse parameters Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 53/82] host reuse: Jiggle the infra-priority a bit, within a flight Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 54/82] host reuse: Use literal for the hosts_infraprioritygroup runvar Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 55/82] host reuse: Bump host share reuse bonus Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 56/82] subst_netboot_template: Do not use all of %r Ian Jackson
2020-10-07 17:59 ` [OSSTEST PATCH 57/82] TestSupport: Provide runvar_is_synth Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 58/82] runvar access: Introduce access control machinery Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 59/82] runvar access: Provide runvar_glob Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 60/82] runvar access: Use runvar_glob for dmrestrict runvar search Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 61/82] runvar access: Introduce sharing_for_build Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 62/82] runvar access: Introduce effects_gone_before_share_reuse Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 63/82] test host reuse: Switch to principled sharing scope runvar scheme Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 64/82] hsot reuse: Hash the share type Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 65/82] hsot reuse: Make share type hash more easily greppable Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 66/82] host lifecycle: Machinery, db, for tracking relevant events Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 67/82] host lifecycle: Fix detection of concurrent jobs Ian Jackson
2020-10-07 18:00 ` Ian Jackson [this message]
2020-10-07 18:00 ` [OSSTEST PATCH 69/82] host lifecycle: Record lifecycle in db and runvar Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 70/82] sg-report-flight: Refactor runvar access Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 71/82] resource reporting, nfc: split a here document Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 72/82] resource reporting: Report host reuse/sharing in job report Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 73/82] host reuse: sg-run-job: Reanme post-test-ok parameter Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 74/82] host reuse: ts-host-reuse: Prepare for argument handling Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 75/82] host reuse: New protocol between sg-run-job and ts-host-reuse Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 76/82] sg-report-flight: Reformat slightly Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 77/82] sg-report-flight: Improvements to other job (share/reuse) reporting Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 78/82] flight other job reporting: Put nulls last in the report Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 79/82] flight other job reporting: Further improvements to ordering Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 80/82] tsreadconfig: Change misleading "setting" message Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 81/82] sg-report-flight: Sharing reports: more task finished info Ian Jackson
2020-10-07 18:00 ` [OSSTEST PATCH 82/82] sg-report-flight: Word-wrapping improvements to job and step names Ian Jackson
2020-10-07 18:22 ` [OSSTEST PATCH 00/82] Reuse test hosts 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=20201007180024.7932-69-iwj@xenproject.org \
    --to=iwj@xenproject.org \
    --cc=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).