pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Relax lock level for setting PGPROC->statusFlags
Date: Wed, 18 Nov 2020 16:26:04 +0000
Message-ID: <E1kfQHU-0004kJ-5U@gemulon.postgresql.org> (raw)

Relax lock level for setting PGPROC->statusFlags

We don't actually need a lock to set PGPROC->statusFlags itself; what we
do need is a shared lock on either XidGenLock or ProcArrayLock in order to
ensure MyProc->pgxactoff keeps still while we modify the mirror array in
ProcGlobal->statusFlags.  Some places were using an exclusive lock for
that, which is excessive.  Relax those to use shared lock only.

procarray.c has a couple of places with somewhat brittle assumptions
about PGPROC changes: ProcArrayEndTransaction uses only shared lock, so
it's permissible to change MyProc only.  On the other hand,
ProcArrayEndTransactionInternal also changes other procs, so it must
hold exclusive lock.  Add asserts to ensure those assumptions continue
to hold.

Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/20201117155501.GA13805@alvherre.pgsql

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/27838981be9de35d54ffcdc6cc06b5d5ea9e0cee

Modified Files
--------------
src/backend/commands/vacuum.c             | 2 +-
src/backend/replication/logical/logical.c | 2 +-
src/backend/replication/slot.c            | 2 +-
src/backend/storage/ipc/procarray.c       | 8 +++++++-
src/backend/storage/lmgr/deadlock.c       | 2 +-
src/include/storage/proc.h                | 5 +++++
6 files changed, 16 insertions(+), 5 deletions(-)



Message-ID: <E1kfQHU-0004kJ-5U@gemulon.postgresql.org>
Permalink:  ../E1kfQHU-0004kJ-5U@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kfQHU-0004kJ-5U@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: alvherre@alvh.no-ip.org
  Subject: Re: pgsql: Relax lock level for setting PGPROC->statusFlags
  In-Reply-To: <E1kfQHU-0004kJ-5U@gemulon.postgresql.org>
  References: <E1kfQHU-0004kJ-5U@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