Fix the initialization of atomic variable introduced by the
authorAmit Kapila
Tue, 13 Nov 2018 05:06:59 +0000 (10:36 +0530)
committerAmit Kapila
Tue, 13 Nov 2018 05:06:59 +0000 (10:36 +0530)
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[email protected]

src/backend/storage/lmgr/proc.c

index bfa84992ea318a4c02dcf5b0bab39bd2d40e44a2..51882642ff55dc06437bfbe6b72ce148bde19f49 100644 (file)
@@ -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);