Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a455878

Browse files
committed
Rename PGPROC fields related to group XID clearing again.
Commit 0e141c0 introduced a new facility to reduce ProcArrayLock contention by clearing several XIDs from the ProcArray under a single lock acquisition. The names initially chosen were deemed not to be very good choices, so commit 4aec498 renamed them. But now it seems like we still didn't get it right. A pending patch wants to add similar infrastructure for batching CLOG updates, so the names need to be clear enough to allow a new set of structure members with a related purpose. Amit Kapila
1 parent 4c9864b commit a455878

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

src/backend/storage/ipc/procarray.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,14 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
497497
Assert(TransactionIdIsValid(allPgXact[proc->pgprocno].xid));
498498

499499
/* Add ourselves to the list of processes needing a group XID clear. */
500-
proc->clearXid = true;
501-
proc->backendLatestXid = latestXid;
500+
proc->procArrayGroupMember = true;
501+
proc->procArrayGroupMemberXid = latestXid;
502502
while (true)
503503
{
504-
nextidx = pg_atomic_read_u32(&procglobal->firstClearXidElem);
505-
pg_atomic_write_u32(&proc->nextClearXidElem, nextidx);
504+
nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
505+
pg_atomic_write_u32(&proc->procArrayGroupNext, nextidx);
506506

507-
if (pg_atomic_compare_exchange_u32(&procglobal->firstClearXidElem,
507+
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
508508
&nextidx,
509509
(uint32) proc->pgprocno))
510510
break;
@@ -523,12 +523,12 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
523523
{
524524
/* acts as a read barrier */
525525
PGSemaphoreLock(&proc->sem);
526-
if (!proc->clearXid)
526+
if (!proc->procArrayGroupMember)
527527
break;
528528
extraWaits++;
529529
}
530530

531-
Assert(pg_atomic_read_u32(&proc->nextClearXidElem) == INVALID_PGPROCNO);
531+
Assert(pg_atomic_read_u32(&proc->procArrayGroupNext) == INVALID_PGPROCNO);
532532

533533
/* Fix semaphore count for any absorbed wakeups */
534534
while (extraWaits-- > 0)
@@ -546,8 +546,8 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
546546
*/
547547
while (true)
548548
{
549-
nextidx = pg_atomic_read_u32(&procglobal->firstClearXidElem);
550-
if (pg_atomic_compare_exchange_u32(&procglobal->firstClearXidElem,
549+
nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
550+
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
551551
&nextidx,
552552
INVALID_PGPROCNO))
553553
break;
@@ -562,10 +562,10 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
562562
PGPROC *proc = &allProcs[nextidx];
563563
PGXACT *pgxact = &allPgXact[nextidx];
564564

565-
ProcArrayEndTransactionInternal(proc, pgxact, proc->backendLatestXid);
565+
ProcArrayEndTransactionInternal(proc, pgxact, proc->procArrayGroupMemberXid);
566566

567567
/* Move to next proc in list. */
568-
nextidx = pg_atomic_read_u32(&proc->nextClearXidElem);
568+
nextidx = pg_atomic_read_u32(&proc->procArrayGroupNext);
569569
}
570570

571571
/* We're done with the lock now. */
@@ -582,13 +582,13 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
582582
{
583583
PGPROC *proc = &allProcs[wakeidx];
584584

585-
wakeidx = pg_atomic_read_u32(&proc->nextClearXidElem);
586-
pg_atomic_write_u32(&proc->nextClearXidElem, INVALID_PGPROCNO);
585+
wakeidx = pg_atomic_read_u32(&proc->procArrayGroupNext);
586+
pg_atomic_write_u32(&proc->procArrayGroupNext, INVALID_PGPROCNO);
587587

588588
/* ensure all previous writes are visible before follower continues. */
589589
pg_write_barrier();
590590

591-
proc->clearXid = false;
591+
proc->procArrayGroupMember = false;
592592

593593
if (proc != MyProc)
594594
PGSemaphoreUnlock(&proc->sem);

src/backend/storage/lmgr/proc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ InitProcGlobal(void)
181181
ProcGlobal->startupBufferPinWaitBufId = -1;
182182
ProcGlobal->walwriterLatch = NULL;
183183
ProcGlobal->checkpointerLatch = NULL;
184-
pg_atomic_init_u32(&ProcGlobal->firstClearXidElem, INVALID_PGPROCNO);
184+
pg_atomic_init_u32(&ProcGlobal->procArrayGroupFirst, INVALID_PGPROCNO);
185185

186186
/*
187187
* Create and initialize all the PGPROC structures we'll need. There are
@@ -396,9 +396,9 @@ InitProcess(void)
396396
SHMQueueElemInit(&(MyProc->syncRepLinks));
397397

398398
/* Initialize fields for group XID clearing. */
399-
MyProc->clearXid = false;
400-
MyProc->backendLatestXid = InvalidTransactionId;
401-
pg_atomic_init_u32(&MyProc->nextClearXidElem, INVALID_PGPROCNO);
399+
MyProc->procArrayGroupMember = false;
400+
MyProc->procArrayGroupMemberXid = InvalidTransactionId;
401+
pg_atomic_init_u32(&MyProc->procArrayGroupNext, INVALID_PGPROCNO);
402402

403403
/* Check that group locking fields are in a proper initial state. */
404404
Assert(MyProc->lockGroupLeaderIdentifier == 0);

src/include/storage/proc.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,15 @@ struct PGPROC
142142
struct XidCache subxids; /* cache for subtransaction XIDs */
143143

144144
/* Support for group XID clearing. */
145-
bool clearXid;
146-
pg_atomic_uint32 nextClearXidElem;
147-
TransactionId backendLatestXid;
145+
/* true, if member of ProcArray group waiting for XID clear */
146+
bool procArrayGroupMember;
147+
/* next ProcArray group member waiting for XID clear */
148+
pg_atomic_uint32 procArrayGroupNext;
149+
/*
150+
* latest transaction id among the transaction's main XID and
151+
* subtransactions
152+
*/
153+
TransactionId procArrayGroupMemberXid;
148154

149155
/* Per-backend LWLock. Protects fields below. */
150156
LWLock backendLock;
@@ -217,7 +223,7 @@ typedef struct PROC_HDR
217223
/* Head of list of bgworker free PGPROC structures */
218224
PGPROC *bgworkerFreeProcs;
219225
/* First pgproc waiting for group XID clear */
220-
pg_atomic_uint32 firstClearXidElem;
226+
pg_atomic_uint32 procArrayGroupFirst;
221227
/* WALWriter process's latch */
222228
Latch *walwriterLatch;
223229
/* Checkpointer process's latch */

0 commit comments

Comments
 (0)