pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17368: Assert failed in GetSafeSnapshot() for SERIALIZABLE READ ONLY DEFERRABLE transaction
Date: Wed, 8 Mar 2023 23:00:00 +0300
Message-ID: <33d30d9c-9491-386e-d19f-b58861683fe2@gmail.com> (raw)
In-Reply-To: <CA+hUKGKT1RCYcy_p8RKGs0C5-8c2=J38xMOcYTxsPL=x6sr-cA@mail.gmail.com>
References: <17368-98a4f99e8e4b4402@postgresql.org>
	<18a116d2-7927-6a62-aa60-ab16c53183f9@gmail.com>
	<CA+hUKG+4m+fvnM_Czyp3Z_h4SaqmwR7sq9XE=k0GcaL_afEfUA@mail.gmail.com>
	<CA+hUKGKYLSa4S7cMYgZXXA+cNTdr1COWtNj1HSc-Y62jwWmv7w@mail.gmail.com>
	<CA+hUKGKT1RCYcy_p8RKGs0C5-8c2=J38xMOcYTxsPL=x6sr-cA@mail.gmail.com>

Hi Thomas,

08.03.2023 14:57, Thomas Munro wrote:
> On Tue, Mar 7, 2023 at 12:39 PM Thomas Munro <thomas.munro@gmail.com> wrote:
>> Scratch that.  I like the more ambitious idea better.  I originally
>> thought it would be less back-patchable, but that's nonsense -- this
>> was a straight up thinko in ancient commit bdaabb9b and we should just
>> fix it properly.  That is, we should treat this case as a
>> generalisation of the the PredXact->WritableSxactCount == 0 case, it's
>> just that we had to do more work to figure that out.  Here's a patch
>> like that.
> Here's a better version.  I plan to push this tomorrow if there are no
> objections.

Just in case you find a test for the fix useful, maybe the attached
patch could be added to the commit.
(It triggers the assert on unpatched master.)

Best regards,
Alexander

Attachments:

Test-for-race-in-SERIALIZABLE-READ-ONLY.patch (text/x-patch, 2.2K) download diff --git a/src/test/isolation/expected/read-only-anomaly-3.out b/src/test/isolation/expected/read-only-anomaly-3.out index 4f7d3f863d..dbaf01944e 100644 --- a/src/test/isolation/expected/read-only-anomaly-3.out +++ b/src/test/isolation/expected/read-only-anomaly-3.out @@ -1,6 +1,6 @@ -Parsed test spec with 3 sessions +Parsed test spec with 4 sessions -starting permutation: s2rx s2ry s1ry s1wy s1c s3r s2wx s2c s3c +starting permutation: s2rx s2ry s1ry s1wy s1c s3r s2wx s2c s3c s4c step s2rx: SELECT balance FROM bank_account WHERE id = 'X'; balance ------- @@ -32,3 +32,30 @@ Y | 20 (2 rows) step s3c: COMMIT; +step s4c: COMMIT; + +starting permutation: s2ry s1wy s1c s2wx s4to s4wx s4c s3r s2c s3c +step s2ry: SELECT balance FROM bank_account WHERE id = 'Y'; +balance +------- + 0 +(1 row) + +step s1wy: UPDATE bank_account SET balance = 20 WHERE id = 'Y'; +step s1c: COMMIT; +step s2wx: UPDATE bank_account SET balance = -11 WHERE id = 'X'; +step s4to: SET lock_timeout = '10ms' +step s4wx: UPDATE bank_account SET balance = -11 WHERE id = 'X'; <waiting ...> +step s4wx: <... completed> +ERROR: canceling statement due to lock timeout +step s4c: COMMIT; +step s3r: SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; +id|balance +--+------- +X | 0 +Y | 20 +(2 rows) + +step s2c: COMMIT; +ERROR: could not serialize access due to read/write dependencies among transactions +step s3c: COMMIT; diff --git a/src/test/isolation/specs/read-only-anomaly-3.spec b/src/test/isolation/specs/read-only-anomaly-3.spec index 61d9c0b9e0..626b66a15a 100644 --- a/src/test/isolation/specs/read-only-anomaly-3.spec +++ b/src/test/isolation/specs/read-only-anomaly-3.spec @@ -36,4 +36,11 @@ setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE; } step s3r { SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; } step s3c { COMMIT; } -permutation s2rx s2ry s1ry s1wy s1c s3r s2wx s2c s3c +session s4 +setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; } +step s4to { SET lock_timeout = '10ms' } +step s4wx { UPDATE bank_account SET balance = -11 WHERE id = 'X'; } +step s4c { COMMIT; } + +permutation s2rx s2ry s1ry s1wy s1c s3r s2wx s2c s3c s4c +permutation s2ry s1wy s1c s2wx s4to s4wx s4c s3r s2c s3c

view thread (12+ messages)  latest in thread

Message-ID: <33d30d9c-9491-386e-d19f-b58861683fe2@gmail.com>
Permalink:  ../33d30d9c-9491-386e-d19f-b58861683fe2@gmail.com/
Also on:    postgresql.org/message-id/33d30d9c-9491-386e-d19f-b58861683fe2@gmail.com

 ·  · 

reply

Reply instructions:

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

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, thomas.munro@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17368: Assert failed in GetSafeSnapshot() for SERIALIZABLE READ ONLY DEFERRABLE transaction
  In-Reply-To: <33d30d9c-9491-386e-d19f-b58861683fe2@gmail.com>

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

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox