Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee79928

Browse files
committed
Clarify what is protected by WaitLSNLock
Not just WaitLSNState.waitersHeap, but also WaitLSNState.procInfos andupdating of WaitLSNState.minWaitedLSN is protected by WaitLSNLock. Thereis one now documented exclusion on fast-path checking ofWaitLSNProcInfo.inHeap flag.Discussion:https://postgr.es/m/202404030658.hhj3vfxeyhft%40alvherre.pgsql
1 parent25f4242 commitee79928

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

‎src/backend/commands/waitlsn.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ addLSNWaiter(XLogRecPtr lsn)
109109
{
110110
WaitLSNProcInfo*procInfo=&waitLSN->procInfos[MyProcNumber];
111111

112+
LWLockAcquire(WaitLSNLock,LW_EXCLUSIVE);
113+
112114
Assert(!procInfo->inHeap);
113115

114116
procInfo->procnum=MyProcNumber;
115117
procInfo->waitLSN=lsn;
116118

117-
LWLockAcquire(WaitLSNLock,LW_EXCLUSIVE);
118-
119119
pairingheap_add(&waitLSN->waitersHeap,&procInfo->phNode);
120120
procInfo->inHeap= true;
121121
updateMinWaitedLSN();
@@ -203,6 +203,12 @@ WaitLSNSetLatches(XLogRecPtr currentLSN)
203203
void
204204
WaitLSNCleanup(void)
205205
{
206+
/*
207+
* We do a fast-path check of the 'inHeap' flag without the lock. This
208+
* flag is set to true only by the process itself. So, it's only possible
209+
* to get a false positive. But that will be eliminated by a recheck
210+
* inside deleteLSNWaiter().
211+
*/
206212
if (waitLSN->procInfos[MyProcNumber].inHeap)
207213
deleteLSNWaiter();
208214
}

‎src/include/commands/waitlsn.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef struct WaitLSNState
4949
/*
5050
* The minimum LSN value some process is waiting for. Used for the
5151
* fast-path checking if we need to wake up any waiters after replaying a
52-
* WAL record.
52+
* WAL record. Could be read lock-less. Update protected by WaitLSNLock.
5353
*/
5454
pg_atomic_uint64minWaitedLSN;
5555

@@ -59,7 +59,10 @@ typedef struct WaitLSNState
5959
*/
6060
pairingheapwaitersHeap;
6161

62-
/* An array with per-process information, indexed by the process number */
62+
/*
63+
* An array with per-process information, indexed by the process number.
64+
* Protected by WaitLSNLock.
65+
*/
6366
WaitLSNProcInfoprocInfos[FLEXIBLE_ARRAY_MEMBER];
6467
}WaitLSNState;
6568

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp