Skip to content

Commit 38a2379

Browse files
committed
Change some bogus PageGetLSN calls to BufferGetLSNAtomic
As src/backend/access/transam/README says, PageGetLSN may only be called by processes holding either exclusive lock on buffer, or a shared lock on buffer plus buffer header lock. Therefore any place that only holds a shared buffer lock must use BufferGetLSNAtomic instead of PageGetLSN, which internally obtains buffer header lock prior to reading the LSN. A few callsites failed to comply with this rule. This was detected by running all tests under a new (not committed) assertion that verifies PageGetLSN locking contract. All but one of the callsites that failed the assertion are fixed by this patch. Remaining callsites were inspected manually and determined not to need any change. The exception (unfixed callsite) is in TestForOldSnapshot, which only has a Page argument, making it impossible to access the corresponding Buffer from it. Fixing that seems a much larger patch that will have to be done separately; and that's just as well, since it was only introduced in 9.6 and other bugs are much older. Some of these bugs are ancient; backpatch all the way back to 9.3. Authors: Jacob Champion, Asim Praveen, Ashwin Agrawal Reviewed-by: Michaël Paquier Discussion: https://postgr.es/m/CABAq_6GXgQDVu3u12mK9O5Xt5abBZWQ0V40LZCE+oUf95XyNFg@mail.gmail.com
1 parent 6c31ac1 commit 38a2379

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/backend/access/gist/gist.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace, GISTSTATE *giststate)
566566
}
567567

568568
stack->page = (Page) BufferGetPage(stack->buffer);
569-
stack->lsn = PageGetLSN(stack->page);
569+
stack->lsn = xlocked ?
570+
PageGetLSN(stack->page) : BufferGetLSNAtomic(stack->buffer);
570571
Assert(!RelationNeedsWAL(state.r) || !XLogRecPtrIsInvalid(stack->lsn));
571572

572573
/*
@@ -816,7 +817,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum)
816817
break;
817818
}
818819

819-
top->lsn = PageGetLSN(page);
820+
top->lsn = BufferGetLSNAtomic(buffer);
820821

821822
/*
822823
* If F_FOLLOW_RIGHT is set, the page to the right doesn't have a

src/backend/access/gist/gistvacuum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ gistbulkdelete(PG_FUNCTION_ARGS)
257257

258258
ptr = (GistBDItem *) palloc(sizeof(GistBDItem));
259259
ptr->blkno = ItemPointerGetBlockNumber(&(idxtuple->t_tid));
260-
ptr->parentlsn = PageGetLSN(page);
260+
ptr->parentlsn = BufferGetLSNAtomic(buffer);
261261
ptr->next = stack->next;
262262
stack->next = ptr;
263263

src/backend/access/nbtree/nbtsearch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
11571157
* safe to apply LP_DEAD hints to the page later. This allows us to drop
11581158
* the pin for MVCC scans, which allows vacuum to avoid blocking.
11591159
*/
1160-
so->currPos.lsn = PageGetLSN(page);
1160+
so->currPos.lsn = BufferGetLSNAtomic(so->currPos.buf);
11611161

11621162
/*
11631163
* we must save the page's right-link while scanning it; this tells us

src/backend/access/nbtree/nbtutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ _bt_killitems(IndexScanDesc scan)
17701770
return;
17711771

17721772
page = BufferGetPage(buf);
1773-
if (PageGetLSN(page) == so->currPos.lsn)
1773+
if (BufferGetLSNAtomic(buf) == so->currPos.lsn)
17741774
so->currPos.buf = buf;
17751775
else
17761776
{

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