Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit272c2ab

Browse files
committed
Change some bogus PageGetLSN calls to BufferGetLSNAtomic
As src/backend/access/transam/README says, PageGetLSN may only be calledby processes holding either exclusive lock on buffer, or a shared lockon buffer plus buffer header lock. Therefore any place that only holdsa 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 byrunning all tests under a new (not committed) assertion that verifiesPageGetLSN locking contract. All but one of the callsites that failedthe assertion are fixed by this patch. Remaining callsites wereinspected manually and determined not to need any change.The exception (unfixed callsite) is in TestForOldSnapshot, which onlyhas a Page argument, making it impossible to access the correspondingBuffer from it. Fixing that seems a much larger patch that will have tobe done separately; and that's just as well, since it was onlyintroduced 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 AgrawalReviewed-by: Michaël PaquierDiscussion:https://postgr.es/m/CABAq_6GXgQDVu3u12mK9O5Xt5abBZWQ0V40LZCE+oUf95XyNFg@mail.gmail.com
1 parent11b623d commit272c2ab

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

‎src/backend/access/gist/gist.c

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

642642
stack->page= (Page)BufferGetPage(stack->buffer);
643-
stack->lsn=PageGetLSN(stack->page);
643+
stack->lsn=xlocked ?
644+
PageGetLSN(stack->page) :BufferGetLSNAtomic(stack->buffer);
644645
Assert(!RelationNeedsWAL(state.r)|| !XLogRecPtrIsInvalid(stack->lsn));
645646

646647
/*
@@ -890,7 +891,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum)
890891
break;
891892
}
892893

893-
top->lsn=PageGetLSN(page);
894+
top->lsn=BufferGetLSNAtomic(buffer);
894895

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

‎src/backend/access/gist/gistget.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ gistkillitems(IndexScanDesc scan)
6161
* read. killedItems could be not valid so LP_DEAD hints applying is not
6262
* safe.
6363
*/
64-
if (PageGetLSN(page)!=so->curPageLSN)
64+
if (BufferGetLSNAtomic(buffer)!=so->curPageLSN)
6565
{
6666
UnlockReleaseBuffer(buffer);
6767
so->numKilled=0;/* reset counter */
@@ -384,7 +384,7 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem, double *myDistances,
384384
* safe to apply LP_DEAD hints to the page later. This allows us to drop
385385
* the pin for MVCC scans, which allows vacuum to avoid blocking.
386386
*/
387-
so->curPageLSN=PageGetLSN(page);
387+
so->curPageLSN=BufferGetLSNAtomic(buffer);
388388

389389
/*
390390
* check all tuples on page

‎src/backend/access/gist/gistvacuum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ gistbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
249249

250250
ptr= (GistBDItem*)palloc(sizeof(GistBDItem));
251251
ptr->blkno=ItemPointerGetBlockNumber(&(idxtuple->t_tid));
252-
ptr->parentlsn=PageGetLSN(page);
252+
ptr->parentlsn=BufferGetLSNAtomic(buffer);
253253
ptr->next=stack->next;
254254
stack->next=ptr;
255255

‎src/backend/access/nbtree/nbtsearch.c

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

12291229
/*
12301230
* 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
@@ -1772,7 +1772,7 @@ _bt_killitems(IndexScanDesc scan)
17721772
return;
17731773

17741774
page=BufferGetPage(buf);
1775-
if (PageGetLSN(page)==so->currPos.lsn)
1775+
if (BufferGetLSNAtomic(buf)==so->currPos.lsn)
17761776
so->currPos.buf=buf;
17771777
else
17781778
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp