Skip to content

Commit c618796

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 9162560 commit c618796

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/backend/access/gist/gist.c

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

560560
stack->page = (Page) BufferGetPage(stack->buffer);
561-
stack->lsn = PageGetLSN(stack->page);
561+
stack->lsn = xlocked ?
562+
PageGetLSN(stack->page) : BufferGetLSNAtomic(stack->buffer);
562563
Assert(!RelationNeedsWAL(state.r) || !XLogRecPtrIsInvalid(stack->lsn));
563564

564565
/*
@@ -808,7 +809,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum)
808809
break;
809810
}
810811

811-
top->lsn = PageGetLSN(page);
812+
top->lsn = BufferGetLSNAtomic(buffer);
812813

813814
/*
814815
* 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

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