diff options
author | Amit Kapila <akapila@postgresql.org> | 2018-11-13 10:36:59 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2018-11-13 10:36:59 +0530 |
commit | d1a2fa3d9901c1e8f6bba1cecbb4ecdd64f4849e (patch) | |
tree | c321e662517f949c00ced245c307c62599ffe241 | |
parent | 5574a0181962195f355863940f1c010f8e9875f6 (diff) | |
download | postgresql-d1a2fa3d9901c1e8f6bba1cecbb4ecdd64f4849e.tar.gz postgresql-d1a2fa3d9901c1e8f6bba1cecbb4ecdd64f4849e.zip |
Fix the initialization of atomic variable introduced by the
group clearing mechanism.
Commit 0e141c0fbb introduced initialization of atomic variable in
InitProcess which means that it's not safe to look at it for backends that
aren't currently in use. Fix that by initializing the same during postmaster
startup.
Reported-by: Andres Freund
Author: Amit Kapila
Backpatch-through: 9.6
Discussion:https://postgr.es/m/20181027104138.qmbbelopvy7cw2qv@alap3.anarazel.de
-rw-r--r-- | src/backend/storage/lmgr/proc.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index bfa84992ea3..51882642ff5 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -266,6 +266,12 @@ InitProcGlobal(void) /* Initialize lockGroupMembers list. */ dlist_init(&procs[i].lockGroupMembers); + + /* + * Initialize the atomic variable, otherwise, it won't be safe to + * access it for backends that aren't currently in use. + */ + pg_atomic_init_u32(&(procs[i].procArrayGroupNext), INVALID_PGPROCNO); } /* @@ -399,7 +405,7 @@ InitProcess(void) /* Initialize fields for group XID clearing. */ MyProc->procArrayGroupMember = false; MyProc->procArrayGroupMemberXid = InvalidTransactionId; - pg_atomic_init_u32(&MyProc->procArrayGroupNext, INVALID_PGPROCNO); + Assert(pg_atomic_read_u32(&MyProc->procArrayGroupNext) == INVALID_PGPROCNO); /* Check that group locking fields are in a proper initial state. */ Assert(MyProc->lockGroupLeader == NULL); |