mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Rename PGPROC fields related to group XID clearing again.
Commit0e141c0fbb
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 commit4aec49899e
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
This commit is contained in:
@ -497,14 +497,14 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
|
|||||||
Assert(TransactionIdIsValid(allPgXact[proc->pgprocno].xid));
|
Assert(TransactionIdIsValid(allPgXact[proc->pgprocno].xid));
|
||||||
|
|
||||||
/* Add ourselves to the list of processes needing a group XID clear. */
|
/* Add ourselves to the list of processes needing a group XID clear. */
|
||||||
proc->clearXid = true;
|
proc->procArrayGroupMember = true;
|
||||||
proc->backendLatestXid = latestXid;
|
proc->procArrayGroupMemberXid = latestXid;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
nextidx = pg_atomic_read_u32(&procglobal->firstClearXidElem);
|
nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
|
||||||
pg_atomic_write_u32(&proc->nextClearXidElem, nextidx);
|
pg_atomic_write_u32(&proc->procArrayGroupNext, nextidx);
|
||||||
|
|
||||||
if (pg_atomic_compare_exchange_u32(&procglobal->firstClearXidElem,
|
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
|
||||||
&nextidx,
|
&nextidx,
|
||||||
(uint32) proc->pgprocno))
|
(uint32) proc->pgprocno))
|
||||||
break;
|
break;
|
||||||
@ -523,12 +523,12 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
|
|||||||
{
|
{
|
||||||
/* acts as a read barrier */
|
/* acts as a read barrier */
|
||||||
PGSemaphoreLock(&proc->sem);
|
PGSemaphoreLock(&proc->sem);
|
||||||
if (!proc->clearXid)
|
if (!proc->procArrayGroupMember)
|
||||||
break;
|
break;
|
||||||
extraWaits++;
|
extraWaits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(pg_atomic_read_u32(&proc->nextClearXidElem) == INVALID_PGPROCNO);
|
Assert(pg_atomic_read_u32(&proc->procArrayGroupNext) == INVALID_PGPROCNO);
|
||||||
|
|
||||||
/* Fix semaphore count for any absorbed wakeups */
|
/* Fix semaphore count for any absorbed wakeups */
|
||||||
while (extraWaits-- > 0)
|
while (extraWaits-- > 0)
|
||||||
@ -546,8 +546,8 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
|
|||||||
*/
|
*/
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
nextidx = pg_atomic_read_u32(&procglobal->firstClearXidElem);
|
nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
|
||||||
if (pg_atomic_compare_exchange_u32(&procglobal->firstClearXidElem,
|
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
|
||||||
&nextidx,
|
&nextidx,
|
||||||
INVALID_PGPROCNO))
|
INVALID_PGPROCNO))
|
||||||
break;
|
break;
|
||||||
@ -562,10 +562,10 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
|
|||||||
PGPROC *proc = &allProcs[nextidx];
|
PGPROC *proc = &allProcs[nextidx];
|
||||||
PGXACT *pgxact = &allPgXact[nextidx];
|
PGXACT *pgxact = &allPgXact[nextidx];
|
||||||
|
|
||||||
ProcArrayEndTransactionInternal(proc, pgxact, proc->backendLatestXid);
|
ProcArrayEndTransactionInternal(proc, pgxact, proc->procArrayGroupMemberXid);
|
||||||
|
|
||||||
/* Move to next proc in list. */
|
/* Move to next proc in list. */
|
||||||
nextidx = pg_atomic_read_u32(&proc->nextClearXidElem);
|
nextidx = pg_atomic_read_u32(&proc->procArrayGroupNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're done with the lock now. */
|
/* We're done with the lock now. */
|
||||||
@ -582,13 +582,13 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
|
|||||||
{
|
{
|
||||||
PGPROC *proc = &allProcs[wakeidx];
|
PGPROC *proc = &allProcs[wakeidx];
|
||||||
|
|
||||||
wakeidx = pg_atomic_read_u32(&proc->nextClearXidElem);
|
wakeidx = pg_atomic_read_u32(&proc->procArrayGroupNext);
|
||||||
pg_atomic_write_u32(&proc->nextClearXidElem, INVALID_PGPROCNO);
|
pg_atomic_write_u32(&proc->procArrayGroupNext, INVALID_PGPROCNO);
|
||||||
|
|
||||||
/* ensure all previous writes are visible before follower continues. */
|
/* ensure all previous writes are visible before follower continues. */
|
||||||
pg_write_barrier();
|
pg_write_barrier();
|
||||||
|
|
||||||
proc->clearXid = false;
|
proc->procArrayGroupMember = false;
|
||||||
|
|
||||||
if (proc != MyProc)
|
if (proc != MyProc)
|
||||||
PGSemaphoreUnlock(&proc->sem);
|
PGSemaphoreUnlock(&proc->sem);
|
||||||
|
@ -181,7 +181,7 @@ InitProcGlobal(void)
|
|||||||
ProcGlobal->startupBufferPinWaitBufId = -1;
|
ProcGlobal->startupBufferPinWaitBufId = -1;
|
||||||
ProcGlobal->walwriterLatch = NULL;
|
ProcGlobal->walwriterLatch = NULL;
|
||||||
ProcGlobal->checkpointerLatch = NULL;
|
ProcGlobal->checkpointerLatch = NULL;
|
||||||
pg_atomic_init_u32(&ProcGlobal->firstClearXidElem, INVALID_PGPROCNO);
|
pg_atomic_init_u32(&ProcGlobal->procArrayGroupFirst, INVALID_PGPROCNO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create and initialize all the PGPROC structures we'll need. There are
|
* Create and initialize all the PGPROC structures we'll need. There are
|
||||||
@ -396,9 +396,9 @@ InitProcess(void)
|
|||||||
SHMQueueElemInit(&(MyProc->syncRepLinks));
|
SHMQueueElemInit(&(MyProc->syncRepLinks));
|
||||||
|
|
||||||
/* Initialize fields for group XID clearing. */
|
/* Initialize fields for group XID clearing. */
|
||||||
MyProc->clearXid = false;
|
MyProc->procArrayGroupMember = false;
|
||||||
MyProc->backendLatestXid = InvalidTransactionId;
|
MyProc->procArrayGroupMemberXid = InvalidTransactionId;
|
||||||
pg_atomic_init_u32(&MyProc->nextClearXidElem, INVALID_PGPROCNO);
|
pg_atomic_init_u32(&MyProc->procArrayGroupNext, INVALID_PGPROCNO);
|
||||||
|
|
||||||
/* Check that group locking fields are in a proper initial state. */
|
/* Check that group locking fields are in a proper initial state. */
|
||||||
Assert(MyProc->lockGroupLeaderIdentifier == 0);
|
Assert(MyProc->lockGroupLeaderIdentifier == 0);
|
||||||
|
@ -142,9 +142,15 @@ struct PGPROC
|
|||||||
struct XidCache subxids; /* cache for subtransaction XIDs */
|
struct XidCache subxids; /* cache for subtransaction XIDs */
|
||||||
|
|
||||||
/* Support for group XID clearing. */
|
/* Support for group XID clearing. */
|
||||||
bool clearXid;
|
/* true, if member of ProcArray group waiting for XID clear */
|
||||||
pg_atomic_uint32 nextClearXidElem;
|
bool procArrayGroupMember;
|
||||||
TransactionId backendLatestXid;
|
/* next ProcArray group member waiting for XID clear */
|
||||||
|
pg_atomic_uint32 procArrayGroupNext;
|
||||||
|
/*
|
||||||
|
* latest transaction id among the transaction's main XID and
|
||||||
|
* subtransactions
|
||||||
|
*/
|
||||||
|
TransactionId procArrayGroupMemberXid;
|
||||||
|
|
||||||
/* Per-backend LWLock. Protects fields below. */
|
/* Per-backend LWLock. Protects fields below. */
|
||||||
LWLock backendLock;
|
LWLock backendLock;
|
||||||
@ -217,7 +223,7 @@ typedef struct PROC_HDR
|
|||||||
/* Head of list of bgworker free PGPROC structures */
|
/* Head of list of bgworker free PGPROC structures */
|
||||||
PGPROC *bgworkerFreeProcs;
|
PGPROC *bgworkerFreeProcs;
|
||||||
/* First pgproc waiting for group XID clear */
|
/* First pgproc waiting for group XID clear */
|
||||||
pg_atomic_uint32 firstClearXidElem;
|
pg_atomic_uint32 procArrayGroupFirst;
|
||||||
/* WALWriter process's latch */
|
/* WALWriter process's latch */
|
||||||
Latch *walwriterLatch;
|
Latch *walwriterLatch;
|
||||||
/* Checkpointer process's latch */
|
/* Checkpointer process's latch */
|
||||||
|
Reference in New Issue
Block a user