pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix check for conflicting session- vs transaction-level locks.
Date: Sat, 24 Jul 2021 22:36:11 +0000
Message-ID: <E1m7QFf-0005Rm-Lv@gemulon.postgresql.org> (raw)

Fix check for conflicting session- vs transaction-level locks.

We have an implementation restriction that PREPARE TRANSACTION can't
handle cases where both session-lifespan and transaction-lifespan locks
are held on the same lockable object.  (That's because we'd otherwise
need to acquire a new PROCLOCK entry during post-prepare cleanup, which
is an operation that might fail.  The situation can only arise with odd
usages of advisory locks, so removing the restriction is probably not
worth the amount of effort it would take.)  AtPrepare_Locks attempted
to enforce this, but its logic was many bricks shy of a load, because
it only detected cases where the session and transaction locks had the
same lockmode.  Locks of different modes on the same object would lead
to the rather unhelpful message "PANIC: we seem to have dropped a bit
somewhere".

To fix, build a transient hashtable with one entry per locktag,
not one per locktag + mode, and use that to detect conflicts.

Per bug #17122 from Alexander Pyhalov.  This bug is ancient,
so back-patch to all supported branches.

Discussion: https://postgr.es/m/17122-04f3c32098a62233@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f47408cdc19c2bbe357703afd81037b6d12ed3ba

Modified Files
--------------
src/backend/storage/lmgr/lock.c                | 129 ++++++++++++++++++++-----
src/test/regress/expected/prepared_xacts.out   |  16 +++
src/test/regress/expected/prepared_xacts_1.out |  17 ++++
src/test/regress/sql/prepared_xacts.sql        |   6 ++
4 files changed, 144 insertions(+), 24 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1m7QFf-0005Rm-Lv@gemulon.postgresql.org>
Permalink:  ../E1m7QFf-0005Rm-Lv@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1m7QFf-0005Rm-Lv@gemulon.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix check for conflicting session- vs transaction-level locks.
  In-Reply-To: <E1m7QFf-0005Rm-Lv@gemulon.postgresql.org>
  References: <E1m7QFf-0005Rm-Lv@gemulon.postgresql.org>

* 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