mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
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
This commit is contained in:
@ -1741,7 +1741,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params)
|
||||
* MyProc->xid/xmin, otherwise GetOldestNonRemovableTransactionId()
|
||||
* might appear to go backwards, which is probably Not Good.
|
||||
*/
|
||||
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
|
||||
LWLockAcquire(ProcArrayLock, LW_SHARED);
|
||||
MyProc->statusFlags |= PROC_IN_VACUUM;
|
||||
if (params->is_wraparound)
|
||||
MyProc->statusFlags |= PROC_VACUUM_FOR_WRAPAROUND;
|
||||
|
Reference in New Issue
Block a user