pgsql: Fix lock assertions in dshash.c.

From: Thomas Munro <tmunro(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix lock assertions in dshash.c.
Date: 2022-07-11 04:47:09
Message-ID: E1oAlK8-002DkI-4m@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix lock assertions in dshash.c.

dshash.c previously maintained flags to be able to assert that you
didn't hold any partition lock. These flags could get out of sync with
reality in error scenarios.

Get rid of all that, and make assertions about the locks themselves
instead. Since LWLockHeldByMe() loops internally, we don't want to put
that inside another loop over all partition locks. Introduce a new
debugging-only interface LWLockAnyHeldByMe() to avoid that.

This problem was noted by Tom and Andres while reviewing changes to
support the new shared memory stats system, and later showed up in
reality while working on commit 389869af.

Back-patch to 11, where dshash.c arrived.

Reported-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
Reviewed-by: Zhihong Yu <zyu(at)yugabyte(dot)com>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Discussion: https://postgr.es/m/20220311012712.botrpsikaufzteyt@alap3.anarazel.de
Discussion: https://postgr.es/m/CA%2BhUKGJ31Wce6HJ7xnVTKWjFUWQZPBngxfJVx4q0E98pDr3kAw%40mail.gmail.com

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5e7608e81ebb2a9e2a72ab771eba3c620c0b42a6

Modified Files
--------------
src/backend/lib/dshash.c | 35 +++++++++--------------------------
src/backend/storage/lmgr/lwlock.c | 26 ++++++++++++++++++++++++++
src/include/storage/lwlock.h | 1 +
3 files changed, 36 insertions(+), 26 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2022-07-11 04:47:21 pgsql: Fix lock assertions in dshash.c.
Previous Message Thomas Munro 2022-07-11 04:46:56 pgsql: Fix lock assertions in dshash.c.