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

Commit0126838

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 parent1d13565 commit0126838

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
@@ -614,7 +614,8 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace, GISTSTATE *giststate)
614614
}
615615

616616
stack->page= (Page)BufferGetPage(stack->buffer);
617-
stack->lsn=PageGetLSN(stack->page);
617+
stack->lsn=xlocked ?
618+
PageGetLSN(stack->page) :BufferGetLSNAtomic(stack->buffer);
618619
Assert(!RelationNeedsWAL(state.r)|| !XLogRecPtrIsInvalid(stack->lsn));
619620

620621
/*
@@ -864,7 +865,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum)
864865
break;
865866
}
866867

867-
top->lsn=PageGetLSN(page);
868+
top->lsn=BufferGetLSNAtomic(buffer);
868869

869870
/*
870871
* 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
@@ -1168,7 +1168,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
11681168
* safe to apply LP_DEAD hints to the page later. This allows us to drop
11691169
* the pin for MVCC scans, which allows vacuum to avoid blocking.
11701170
*/
1171-
so->currPos.lsn=PageGetLSN(page);
1171+
so->currPos.lsn=BufferGetLSNAtomic(so->currPos.buf);
11721172

11731173
/*
11741174
* 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
@@ -1768,7 +1768,7 @@ _bt_killitems(IndexScanDesc scan)
17681768
return;
17691769

17701770
page=BufferGetPage(buf);
1771-
if (PageGetLSN(page)==so->currPos.lsn)
1771+
if (BufferGetLSNAtomic(buf)==so->currPos.lsn)
17721772
so->currPos.buf=buf;
17731773
else
17741774
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp