Skip to content

Commit a53bc13

Browse files
author
Amit Kapila
committed
Fix the initialization of atomic variables introduced by the
group clearing mechanism. Commits 0e141c0 and baaf272 introduced initialization of atomic variables in InitProcess which means that it's not safe to look at those for backends that aren't currently in use. Fix that by initializing them during postmaster startup. Reported-by: Andres Freund Author: Amit Kapila Backpatch-through: 9.6 Discussion: https://postgr.es/m/20181027104138.qmbbelopvy7cw2qv@alap3.anarazel.de
1 parent 257ef3c commit a53bc13

File tree

1 file changed

+9
-2
lines changed
  • src/backend/storage/lmgr

1 file changed

+9
-2
lines changed

src/backend/storage/lmgr/proc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ InitProcGlobal(void)
267267

268268
/* Initialize lockGroupMembers list. */
269269
dlist_init(&procs[i].lockGroupMembers);
270+
271+
/*
272+
* Initialize the atomic variables, otherwise, it won't be safe to
273+
* access them for backends that aren't currently in use.
274+
*/
275+
pg_atomic_init_u32(&(procs[i].procArrayGroupNext), INVALID_PGPROCNO);
276+
pg_atomic_init_u32(&(procs[i].clogGroupNext), INVALID_PGPROCNO);
270277
}
271278

272279
/*
@@ -401,7 +408,7 @@ InitProcess(void)
401408
/* Initialize fields for group XID clearing. */
402409
MyProc->procArrayGroupMember = false;
403410
MyProc->procArrayGroupMemberXid = InvalidTransactionId;
404-
pg_atomic_init_u32(&MyProc->procArrayGroupNext, INVALID_PGPROCNO);
411+
Assert(pg_atomic_read_u32(&MyProc->procArrayGroupNext) == INVALID_PGPROCNO);
405412

406413
/* Check that group locking fields are in a proper initial state. */
407414
Assert(MyProc->lockGroupLeader == NULL);
@@ -416,7 +423,7 @@ InitProcess(void)
416423
MyProc->clogGroupMemberXidStatus = TRANSACTION_STATUS_IN_PROGRESS;
417424
MyProc->clogGroupMemberPage = -1;
418425
MyProc->clogGroupMemberLsn = InvalidXLogRecPtr;
419-
pg_atomic_init_u32(&MyProc->clogGroupNext, INVALID_PGPROCNO);
426+
Assert(pg_atomic_read_u32(&MyProc->clogGroupNext) == INVALID_PGPROCNO);
420427

421428
/*
422429
* Acquire ownership of the PGPROC's latch, so that we can use WaitLatch

0 commit comments

Comments
 (0)