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

Appearance settings

Commit be2f073

Browse filesBrowse files
committed
Fix zeroing of pg_serial page without SLRU bank lock
Bug in commit 53c2a97: we failed to acquire the correct SLRU bank lock when iterating to zero-out intermediate pages in predicate.c. Rewrite the code block so that we follow the locking protocol correctly. Also update an outdated comment in the same file -- SerialSLRULock exists no more. Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Discussion: https://postgr.es/m/2a25eaf4-a3a4-5fd1-6241-9d7c73142085@gmail.com
1 parent bf1e650 commit be2f073
Copy full SHA for be2f073

File tree

Expand file treeCollapse file tree

1 file changed

+12
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-7
lines changed

‎src/backend/storage/lmgr/predicate.c

Copy file name to clipboardExpand all lines: src/backend/storage/lmgr/predicate.c
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
* SerialControlLock
138138
* - Protects SerialControlData members
139139
*
140-
* SerialSLRULock
140+
* SLRU per-bank locks
141141
* - Protects SerialSlruCtl
142142
*
143143
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
@@ -908,20 +908,25 @@ SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
908908
if (isNewPage)
909909
serialControl->headPage = targetPage;
910910

911-
LWLockAcquire(lock, LW_EXCLUSIVE);
912-
913911
if (isNewPage)
914912
{
915-
/* Initialize intervening pages. */
916-
while (firstZeroPage != targetPage)
913+
/* Initialize intervening pages; might involve trading locks */
914+
for (;;)
917915
{
918-
(void) SimpleLruZeroPage(SerialSlruCtl, firstZeroPage);
916+
lock = SimpleLruGetBankLock(SerialSlruCtl, firstZeroPage);
917+
LWLockAcquire(lock, LW_EXCLUSIVE);
918+
slotno = SimpleLruZeroPage(SerialSlruCtl, firstZeroPage);
919+
if (firstZeroPage == targetPage)
920+
break;
919921
firstZeroPage = SerialNextPage(firstZeroPage);
922+
LWLockRelease(lock);
920923
}
921-
slotno = SimpleLruZeroPage(SerialSlruCtl, targetPage);
922924
}
923925
else
926+
{
927+
LWLockAcquire(lock, LW_EXCLUSIVE);
924928
slotno = SimpleLruReadPage(SerialSlruCtl, targetPage, true, xid);
929+
}
925930

926931
SerialValue(slotno, xid) = minConflictCommitSeqNo;
927932
SerialSlruCtl->shared->page_dirty[slotno] = true;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.