From 27838981be9de35d54ffcdc6cc06b5d5ea9e0cee Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 18 Nov 2020 13:24:22 -0300 Subject: Relax lock level for setting PGPROC->statusFlags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/20201117155501.GA13805@alvherre.pgsql --- src/include/storage/proc.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/include/storage/proc.h') diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 1067f58f51b..00bb244340a 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -98,6 +98,11 @@ typedef enum * The semaphore and lock-activity fields in a prepared-xact PGPROC are unused, * but its myProcLocks[] lists are valid. * + * We allow many fields of this struct to be accessed without locks, such as + * statusFlags or delayChkpt. However, keep in mind that writing mirrored ones + * (see below) requires holding ProcArrayLock or XidGenLock in at least shared + * mode, so that pgxactoff does not change concurrently. + * * Mirrored fields: * * Some fields in PGPROC (see "mirrored in ..." comment) are mirrored into an -- cgit v1.2.3