index a57b818a2d482dd633deb085c50d394a09fdbb6a..1a83c34e09f7328b05c3db9a34c06fe3af3584be 100644 (file)
{
WaitLSNProcInfo *procInfo = &waitLSN->procInfos[MyProcNumber];
+ LWLockAcquire(WaitLSNLock, LW_EXCLUSIVE);
+
Assert(!procInfo->inHeap);
procInfo->procnum = MyProcNumber;
procInfo->waitLSN = lsn;
- LWLockAcquire(WaitLSNLock, LW_EXCLUSIVE);
-
pairingheap_add(&waitLSN->waitersHeap, &procInfo->phNode);
procInfo->inHeap = true;
updateMinWaitedLSN();
void
WaitLSNCleanup(void)
{
+ /*
+ * We do a fast-path check of the 'inHeap' flag without the lock. This
+ * flag is set to true only by the process itself. So, it's only possible
+ * to get a false positive. But that will be eliminated by a recheck
+ * inside deleteLSNWaiter().
+ */
if (waitLSN->procInfos[MyProcNumber].inHeap)
deleteLSNWaiter();
}
index b3d9eed64d816cfd0abc68708ba3317c3c2a9d6e..da17b8be6f9b5223d064dba3f461f01d23813a72 100644 (file)
/*
* The minimum LSN value some process is waiting for. Used for the
* fast-path checking if we need to wake up any waiters after replaying a
- * WAL record.
+ * WAL record. Could be read lock-less. Update protected by WaitLSNLock.
*/
pg_atomic_uint64 minWaitedLSN;
*/
pairingheap waitersHeap;
- /* An array with per-process information, indexed by the process number */
+ /*
+ * An array with per-process information, indexed by the process number.
+ * Protected by WaitLSNLock.
+ */
WaitLSNProcInfo procInfos[FLEXIBLE_ARRAY_MEMBER];
} WaitLSNState;