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

Commit410c422

Browse files
committed
Fix race condition where heap_delete() fails to pin VM page.
Similar to5f12bc9, the code must re-check PageIsAllVisible() afterbuffer lock is re-acquired. Backpatching to the same version, 12.Discussion:https://postgr.es/m/CAEP4nAw9jYQDKd_5Y+-s2E4YiUJq1vqiikFjYGpLShtp-K3gag@mail.gmail.comReported-by: Robins TharakanReviewed-by: Robins TharakanBackpatch-through: 12
1 parent5f9dda4 commit410c422

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,15 @@ heap_delete(Relation relation, ItemPointer tid,
25002500

25012501
LockBuffer(buffer,BUFFER_LOCK_EXCLUSIVE);
25022502

2503+
lp=PageGetItemId(page,ItemPointerGetOffsetNumber(tid));
2504+
Assert(ItemIdIsNormal(lp));
2505+
2506+
tp.t_tableOid=RelationGetRelid(relation);
2507+
tp.t_data= (HeapTupleHeader)PageGetItem(page,lp);
2508+
tp.t_len=ItemIdGetLength(lp);
2509+
tp.t_self=*tid;
2510+
2511+
l1:
25032512
/*
25042513
* If we didn't pin the visibility map page and the page has become all
25052514
* visible while we were busy locking the buffer, we'll have to unlock and
@@ -2513,15 +2522,6 @@ heap_delete(Relation relation, ItemPointer tid,
25132522
LockBuffer(buffer,BUFFER_LOCK_EXCLUSIVE);
25142523
}
25152524

2516-
lp=PageGetItemId(page,ItemPointerGetOffsetNumber(tid));
2517-
Assert(ItemIdIsNormal(lp));
2518-
2519-
tp.t_tableOid=RelationGetRelid(relation);
2520-
tp.t_data= (HeapTupleHeader)PageGetItem(page,lp);
2521-
tp.t_len=ItemIdGetLength(lp);
2522-
tp.t_self=*tid;
2523-
2524-
l1:
25252525
result=HeapTupleSatisfiesUpdate(&tp,cid,buffer);
25262526

25272527
if (result==TM_Invisible)
@@ -2580,8 +2580,12 @@ heap_delete(Relation relation, ItemPointer tid,
25802580
* If xwait had just locked the tuple then some other xact
25812581
* could update this tuple before we get to this point. Check
25822582
* for xmax change, and start over if so.
2583+
*
2584+
* We also must start over if we didn't pin the VM page, and
2585+
* the page has become all visible.
25832586
*/
2584-
if (xmax_infomask_changed(tp.t_data->t_infomask,infomask)||
2587+
if ((vmbuffer==InvalidBuffer&&PageIsAllVisible(page))||
2588+
xmax_infomask_changed(tp.t_data->t_infomask,infomask)||
25852589
!TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
25862590
xwait))
25872591
gotol1;
@@ -2613,8 +2617,12 @@ heap_delete(Relation relation, ItemPointer tid,
26132617
* xwait is done, but if xwait had just locked the tuple then some
26142618
* other xact could update this tuple before we get to this point.
26152619
* Check for xmax change, and start over if so.
2620+
*
2621+
* We also must start over if we didn't pin the VM page, and the
2622+
* page has become all visible.
26162623
*/
2617-
if (xmax_infomask_changed(tp.t_data->t_infomask,infomask)||
2624+
if ((vmbuffer==InvalidBuffer&&PageIsAllVisible(page))||
2625+
xmax_infomask_changed(tp.t_data->t_infomask,infomask)||
26182626
!TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
26192627
xwait))
26202628
gotol1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp