File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -109,13 +109,13 @@ addLSNWaiter(XLogRecPtr lsn)
109
109
{
110
110
WaitLSNProcInfo * procInfo = & waitLSN -> procInfos [MyProcNumber ];
111
111
112
+ LWLockAcquire (WaitLSNLock , LW_EXCLUSIVE );
113
+
112
114
Assert (!procInfo -> inHeap );
113
115
114
116
procInfo -> procnum = MyProcNumber ;
115
117
procInfo -> waitLSN = lsn ;
116
118
117
- LWLockAcquire (WaitLSNLock , LW_EXCLUSIVE );
118
-
119
119
pairingheap_add (& waitLSN -> waitersHeap , & procInfo -> phNode );
120
120
procInfo -> inHeap = true;
121
121
updateMinWaitedLSN ();
@@ -203,6 +203,12 @@ WaitLSNSetLatches(XLogRecPtr currentLSN)
203
203
void
204
204
WaitLSNCleanup (void )
205
205
{
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
+ */
206
212
if (waitLSN -> procInfos [MyProcNumber ].inHeap )
207
213
deleteLSNWaiter ();
208
214
}
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ typedef struct WaitLSNState
49
49
/*
50
50
* The minimum LSN value some process is waiting for. Used for the
51
51
* 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.
53
53
*/
54
54
pg_atomic_uint64 minWaitedLSN ;
55
55
@@ -59,7 +59,10 @@ typedef struct WaitLSNState
59
59
*/
60
60
pairingheap waitersHeap ;
61
61
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
+ */
63
66
WaitLSNProcInfo procInfos [FLEXIBLE_ARRAY_MEMBER ];
64
67
} WaitLSNState ;
65
68
You can’t perform that action at this time.
0 commit comments