summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2024-04-07 00:32:35 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2024-04-07 00:49:53 +0300
commitee79928441e7e291532b833455ebfee27d7cab5c (patch)
treebc8115da4fbef2a910f5f45531b21c9095b716bb /src/backend/commands
parent25f42429e2ff2acca35c9154fc2e36b75c79227a (diff)
Clarify what is protected by WaitLSNLock
Not just WaitLSNState.waitersHeap, but also WaitLSNState.procInfos and updating of WaitLSNState.minWaitedLSN is protected by WaitLSNLock. There is one now documented exclusion on fast-path checking of WaitLSNProcInfo.inHeap flag. Discussion: https://postgr.es/m/202404030658.hhj3vfxeyhft%40alvherre.pgsql
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/waitlsn.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/commands/waitlsn.c b/src/backend/commands/waitlsn.c
index a57b818a2d4..1a83c34e09f 100644
--- a/src/backend/commands/waitlsn.c
+++ b/src/backend/commands/waitlsn.c
@@ -109,13 +109,13 @@ addLSNWaiter(XLogRecPtr lsn)
{
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();
@@ -203,6 +203,12 @@ WaitLSNSetLatches(XLogRecPtr currentLSN)
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();
}