Skip to content

Commit be2f073

Browse 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

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/backend/storage/lmgr/predicate.c

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy