Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TwI8l-0006a6-He for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Jan 2013 20:02:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TwI8l-0005eQ-1m for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Jan 2013 20:02:15 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TwI8i-0005ce-RE for pgsql-hackers@postgresql.org; Fri, 18 Jan 2013 20:02:12 +0000 Received: from smtprelay0025.b.hostedemail.com ([64.98.42.25] helo=smtprelay.b.hostedemail.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TwI8g-0007vN-6I for pgsql-hackers@postgresql.org; Fri, 18 Jan 2013 20:02:12 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay05.b.hostedemail.com (Postfix) with SMTP id 3418A1480363; Fri, 18 Jan 2013 20:02:08 +0000 (UTC) X-Panda: scanned! X-Spam-Summary: 50, 0, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::::::, RULES_HIT:355:379:599:601:871:945:967:973:988:989:1260:1311:1312:1313:1314:1345:1358:1359:1437:1515:1516:1518:1519:1535:1543:1575:1594:1595:1596:1711:1730:1747:1764:1777:1792:2198:2199:2393:2525:2560:2563:2682:2685:2859:2895:2901:2915:2933:2937:2939:2942:2945:2947:2951:2954:3022:3027:3138:3139:3140:3141:3142:3355:3636:3865:3866:3867:3868:3869:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:4659:5007:6261:6748:7281:7679:7809:7903:7909:8957:9025:9121:10004:10400:10450:10455:10848:11232:11256:11257:11473:11604:11657:11658:11914:12043:12438:12517:12519:12555:12679:19904:19999, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:0:0 X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Filterd-Recvd-Size: 5343 Received: from perhan.alvh.no-ip.org (unknown [190.95.28.201]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf11.b.hostedemail.com (Postfix) with ESMTPA; Fri, 18 Jan 2013 20:02:07 +0000 (UTC) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id B99616E0B6; Fri, 18 Jan 2013 17:02:04 -0300 (CLST) Date: Fri, 18 Jan 2013 17:02:04 -0300 From: Alvaro Herrera To: Erik Rijkers Cc: Kevin Grittner , pgsql-hackers@postgresql.org, Andres Freund Subject: Re: foreign key locks Message-ID: <20130118200204.GH4063@alvh.no-ip.org> References: <20121129152326.69330@gmx.com> <20121129160220.GA4942@alvh.no-ip.org> <20121129161654.GB4942@alvh.no-ip.org> <20121228204847.GD4150@alvh.no-ip.org> <20130110210040.GB4110@alvh.no-ip.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="kXdP64Ggrk/fb43R" Content-Disposition: inline In-Reply-To: <20130110210040.GB4110@alvh.no-ip.org> User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --kXdP64Ggrk/fb43R Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Alvaro Herrera wrote: > Here's version 28 of this patch. The only substantive change here from > v26 is that I've made GetTupleForTrigger() use either LockTupleExclusive > or LockTupleNoKeyExclusive, depending on whether the key columns are > being modified by the update. This needs to go through EvalPlanQual, so > that function is now getting the lock mode as a parameter instead of > hardcoded LockTupleExclusive. (All other users of GetTupleForTrigger > still use LockTupleExclusive, so there's no change for anybody other > than FOR EACH ROW BEFORE UPDATE triggers). >=20 > At this point, I think I've done all I wanted to do in connection with > this patch, and I intend to commit. I think this is a good time to get > it committed, so that people can play with it more extensively and > report any breakage I might have caused before we even get into beta. While trying this out this morning I noticed a bug in the XLog code: trying to lock the updated version of a tuple when the page that contains the updated version requires a backup block, would cause this: PANIC: invalid xlog record length 0 The reason is that there is an (unknown to me) rule that there must be some data not associated with a buffer: /* * NOTE: We disallow len =3D=3D 0 because it provides a useful bit of extra * error checking in ReadRecord. This means that all callers of * XLogInsert must supply at least some not-in-a-buffer data. [...] */ This seems pretty strange to me. And having the rule be spelled out only in a comment within XLogInsert and not at its top, and not nearby the XLogRecData struct definition either, seems pretty strange to me. I wonder how come every PG hacker except me knows this. For the curious, I attach an isolationtester spec file I used to reproduce the problem (and verify the fix). To fix the crash I needed to do this: diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/hea= pam.c index 99fced1..9762890 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -4838,7 +4838,7 @@ l4: { xl_heap_lock_updated xlrec; XLogRecPtr recptr; - XLogRecData rdata; + XLogRecData rdata[2]; Page page =3D BufferGetPage(buf); =20 xlrec.target.node =3D rel->rd_node; @@ -4846,13 +4846,18 @@ l4: xlrec.xmax =3D new_xmax; xlrec.infobits_set =3D compute_infobits(new_infomask, new_infomask2); =20 - rdata.data =3D (char *) &xlrec; - rdata.len =3D SizeOfHeapLockUpdated; - rdata.buffer =3D buf; - rdata.buffer_std =3D true; - rdata.next =3D NULL; + rdata[0].data =3D (char *) &xlrec; + rdata[0].len =3D SizeOfHeapLockUpdated; + rdata[0].buffer =3D InvalidBuffer; + rdata[0].next =3D &(rdata[1]); + + rdata[1].data =3D NULL; + rdata[1].len =3D 0; + rdata[1].buffer =3D buf; + rdata[1].buffer_std =3D true; + rdata[1].next =3D NULL; =20 - recptr =3D XLogInsert(RM_HEAP2_ID, XLOG_HEAP2_LOCK_UPDATED, &rdata); + recptr =3D XLogInsert(RM_HEAP2_ID, XLOG_HEAP2_LOCK_UPDATED, rdata); =20 PageSetLSN(page, recptr); PageSetTLI(page, ThisTimeLineID); --=20 =C1lvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --kXdP64Ggrk/fb43R Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="xlog-lock-updated.spec" setup { CREATE TABLE foo ( key serial PRIMARY KEY, value int ); INSERT INTO foo SELECT value FROM generate_series(1, 226) AS value; } teardown { DROP TABLE foo; } session "s1" step "s1b" { BEGIN ISOLATION LEVEL REPEATABLE READ; } step "s1s" { SELECT * FROM foo LIMIT 0; } # obtain snapshot step "s1l" { SELECT * FROM foo WHERE key = 1 FOR KEY SHARE; } # obtain lock step "s1c" { COMMIT; } session "s2" step "s2b" { BEGIN; } step "s2u" { UPDATE foo SET value = 2 WHERE key = 1; } step "s2c" { COMMIT; } session "s3" step "s3ck" { CHECKPOINT; } permutation "s1b" "s1s" "s2b" "s2u" "s3ck" "s1l" "s1c" "s2c" --kXdP64Ggrk/fb43R Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --kXdP64Ggrk/fb43R--