From: Fujii Masao Date: Mon, 22 Feb 2021 09:25:00 +0000 (+0900) Subject: Initialize atomic variable waitStart in PGPROC, at postmaster startup. X-Git-Tag: REL_14_BETA1~724 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=f05ed5a5cfa55878baa77a1e39d68cb09793b477;p=postgresql.git Initialize atomic variable waitStart in PGPROC, at postmaster startup. Commit 46d6e5f567 added the atomic variable "waitStart" into PGPROC struct, to store the time at which wait for lock acquisition started. Previously this variable was initialized every time each backend started. Instead, this commit makes postmaster initialize it at the startup, to ensure that the variable should be initialized before any use of it. This commit also moves the code to initialize "waitStart" variable for prepare transaction, from TwoPhaseGetDummyProc() to MarkAsPreparingGuts(). Because MarkAsPreparingGuts() is more proper place to do that since it initializes other PGPROC variables. Author: Fujii Masao Reviewed-by: Atsushi Torikoshi Discussion: https://postgr.es/m/1df88660-6f08-cc6e-b7e2-f85296a2bdab@oss.nttdata.com --- diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 70d22577cee..c9b13062b0d 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -475,6 +475,7 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid, proc->lwWaitMode = 0; proc->waitLock = NULL; proc->waitProcLock = NULL; + pg_atomic_init_u64(&proc->waitStart, 0); for (i = 0; i < NUM_LOCK_PARTITIONS; i++) SHMQueueInit(&(proc->myProcLocks[i])); /* subxid data must be filled later by GXactLoadSubxactData */ @@ -873,15 +874,8 @@ PGPROC * TwoPhaseGetDummyProc(TransactionId xid, bool lock_held) { GlobalTransaction gxact = TwoPhaseGetGXact(xid, lock_held); - PGPROC *dummy = &ProcGlobal->allProcs[gxact->pgprocno]; - /* - * Initialize atomic variable in dummy proc so that GetLockStatusData() - * can read it later. - */ - pg_atomic_init_u64(&dummy->waitStart, 0); - - return dummy; + return &ProcGlobal->allProcs[gxact->pgprocno]; } /************************************************************************/ diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index db9529a534a..897045ee272 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -281,6 +281,7 @@ InitProcGlobal(void) */ pg_atomic_init_u32(&(procs[i].procArrayGroupNext), INVALID_PGPROCNO); pg_atomic_init_u32(&(procs[i].clogGroupNext), INVALID_PGPROCNO); + pg_atomic_init_u64(&(procs[i].waitStart), 0); } /* @@ -402,7 +403,7 @@ InitProcess(void) MyProc->lwWaitMode = 0; MyProc->waitLock = NULL; MyProc->waitProcLock = NULL; - pg_atomic_init_u64(&MyProc->waitStart, 0); + pg_atomic_write_u64(&MyProc->waitStart, 0); #ifdef USE_ASSERT_CHECKING { int i; @@ -581,7 +582,7 @@ InitAuxiliaryProcess(void) MyProc->lwWaitMode = 0; MyProc->waitLock = NULL; MyProc->waitProcLock = NULL; - pg_atomic_init_u64(&MyProc->waitStart, 0); + pg_atomic_write_u64(&MyProc->waitStart, 0); #ifdef USE_ASSERT_CHECKING { int i;