mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Use ProcNumbers instead of direct Latch pointers to address other procs
This is in preparation for replacing Latches with a new abstraction. That's still work in progress, but this seems a little tidier anyway, so let's get this refactoring out of the way already. Discussion: https://www.postgresql.org/message-id/391abe21-413e-4d91-a650-b663af49500c%40iki.fi
This commit is contained in:
@@ -2671,8 +2671,14 @@ XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
|
||||
wakeup = true;
|
||||
}
|
||||
|
||||
if (wakeup && ProcGlobal->walwriterLatch)
|
||||
SetLatch(ProcGlobal->walwriterLatch);
|
||||
if (wakeup)
|
||||
{
|
||||
volatile PROC_HDR *procglobal = ProcGlobal;
|
||||
ProcNumber walwriterProc = procglobal->walwriterProc;
|
||||
|
||||
if (walwriterProc != INVALID_PROC_NUMBER)
|
||||
SetLatch(&GetPGProcByNumber(walwriterProc)->procLatch);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -112,7 +112,7 @@ addLSNWaiter(XLogRecPtr lsn)
|
||||
|
||||
Assert(!procInfo->inHeap);
|
||||
|
||||
procInfo->latch = MyLatch;
|
||||
procInfo->procno = MyProcNumber;
|
||||
procInfo->waitLSN = lsn;
|
||||
|
||||
pairingheap_add(&waitLSNState->waitersHeap, &procInfo->phNode);
|
||||
@@ -154,16 +154,17 @@ void
|
||||
WaitLSNSetLatches(XLogRecPtr currentLSN)
|
||||
{
|
||||
int i;
|
||||
Latch **wakeUpProcLatches;
|
||||
ProcNumber *wakeUpProcs;
|
||||
int numWakeUpProcs = 0;
|
||||
|
||||
wakeUpProcLatches = palloc(sizeof(Latch *) * MaxBackends);
|
||||
wakeUpProcs = palloc(sizeof(ProcNumber) * MaxBackends);
|
||||
|
||||
LWLockAcquire(WaitLSNLock, LW_EXCLUSIVE);
|
||||
|
||||
/*
|
||||
* Iterate the pairing heap of waiting processes till we find LSN not yet
|
||||
* replayed. Record the process latches to set them later.
|
||||
* replayed. Record the process numbers to wake up, but to avoid holding
|
||||
* the lock for too long, send the wakeups only after releasing the lock.
|
||||
*/
|
||||
while (!pairingheap_is_empty(&waitLSNState->waitersHeap))
|
||||
{
|
||||
@@ -174,7 +175,7 @@ WaitLSNSetLatches(XLogRecPtr currentLSN)
|
||||
procInfo->waitLSN > currentLSN)
|
||||
break;
|
||||
|
||||
wakeUpProcLatches[numWakeUpProcs++] = procInfo->latch;
|
||||
wakeUpProcs[numWakeUpProcs++] = procInfo->procno;
|
||||
(void) pairingheap_remove_first(&waitLSNState->waitersHeap);
|
||||
procInfo->inHeap = false;
|
||||
}
|
||||
@@ -191,9 +192,9 @@ WaitLSNSetLatches(XLogRecPtr currentLSN)
|
||||
*/
|
||||
for (i = 0; i < numWakeUpProcs; i++)
|
||||
{
|
||||
SetLatch(wakeUpProcLatches[i]);
|
||||
SetLatch(&GetPGProcByNumber(wakeUpProcs[i])->procLatch);
|
||||
}
|
||||
pfree(wakeUpProcLatches);
|
||||
pfree(wakeUpProcs);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user