diff options
| author | Tom Lane | 2021-07-24 22:35:52 +0000 |
|---|---|---|
| committer | Tom Lane | 2021-07-24 22:35:52 +0000 |
| commit | 6310809c4aa146b3996a35524955c6c6943d241a (patch) | |
| tree | 67adab0b0aff7c25658a6ab14d5c8d16a004d104 /src/test | |
| parent | 3779ac62d709467fe6331c8f0285d42e7487a01c (diff) | |
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
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/prepared_xacts.out | 16 | ||||
| -rw-r--r-- | src/test/regress/expected/prepared_xacts_1.out | 17 | ||||
| -rw-r--r-- | src/test/regress/sql/prepared_xacts.sql | 6 |
3 files changed, 39 insertions, 0 deletions
diff --git a/src/test/regress/expected/prepared_xacts.out b/src/test/regress/expected/prepared_xacts.out index eb77c18788e..ba8e3ccc6c9 100644 --- a/src/test/regress/expected/prepared_xacts.out +++ b/src/test/regress/expected/prepared_xacts.out @@ -151,6 +151,22 @@ SELECT gid FROM pg_prepared_xacts; -- Clean up DROP TABLE pxtest1; +-- Test detection of session-level and xact-level locks on same object +BEGIN; +SELECT pg_advisory_lock(1); + pg_advisory_lock +------------------ + +(1 row) + +SELECT pg_advisory_xact_lock_shared(1); + pg_advisory_xact_lock_shared +------------------------------ + +(1 row) + +PREPARE TRANSACTION 'foo6'; -- fails +ERROR: cannot PREPARE while holding both session-level and transaction-level locks on the same object -- Test subtransactions BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; CREATE TABLE pxtest2 (a int); diff --git a/src/test/regress/expected/prepared_xacts_1.out b/src/test/regress/expected/prepared_xacts_1.out index 0857d259e07..2cd50ad9470 100644 --- a/src/test/regress/expected/prepared_xacts_1.out +++ b/src/test/regress/expected/prepared_xacts_1.out @@ -153,6 +153,23 @@ SELECT gid FROM pg_prepared_xacts; -- Clean up DROP TABLE pxtest1; +-- Test detection of session-level and xact-level locks on same object +BEGIN; +SELECT pg_advisory_lock(1); + pg_advisory_lock +------------------ + +(1 row) + +SELECT pg_advisory_xact_lock_shared(1); + pg_advisory_xact_lock_shared +------------------------------ + +(1 row) + +PREPARE TRANSACTION 'foo6'; -- fails +ERROR: prepared transactions are disabled +HINT: Set max_prepared_transactions to a nonzero value. -- Test subtransactions BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; CREATE TABLE pxtest2 (a int); diff --git a/src/test/regress/sql/prepared_xacts.sql b/src/test/regress/sql/prepared_xacts.sql index d8249a27dc2..2f0bb55bb49 100644 --- a/src/test/regress/sql/prepared_xacts.sql +++ b/src/test/regress/sql/prepared_xacts.sql @@ -88,6 +88,12 @@ SELECT gid FROM pg_prepared_xacts; -- Clean up DROP TABLE pxtest1; +-- Test detection of session-level and xact-level locks on same object +BEGIN; +SELECT pg_advisory_lock(1); +SELECT pg_advisory_xact_lock_shared(1); +PREPARE TRANSACTION 'foo6'; -- fails + -- Test subtransactions BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; CREATE TABLE pxtest2 (a int); |
