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

Commite7bd2d6

Browse files
committed
Avoid improbable PANIC during heap_update, redux.
Commit34f581c intended to ensure that RelationGetBufferForTuplewould acquire a visibility-map page pin in case the otherBuffer'sall-visible bit had become set since we last had lock on that page.But I missed a case: when we're extending the relation, VM concernswere dealt with only in the relatively-less-likely case that wefail to conditionally lock the otherBuffer. I think I'd believedthat we couldn't need to worry about it if the conditional locksucceeds, which is true for the target buffer; but the otherBufferwas unlocked for awhile so its bit might be set anyway. So we needto do the GetVisibilityMapPins dance, and then also recheck thepage's free space, in both cases.Per report from Jaime Casanova. Back-patch to v12 as the previouspatch was (although there's still no evidence that the bug isreachable pre-v14).Discussion:https://postgr.es/m/E1lWLjP-00006Y-Ml@gemulon.postgresql.org
1 parentd9102e4 commite7bd2d6

File tree

1 file changed

+23
-18
lines changed
  • src/backend/access/heap

1 file changed

+23
-18
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -643,29 +643,34 @@ RelationGetBufferForTuple(Relation relation, Size len,
643643
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
644644
LockBuffer(otherBuffer,BUFFER_LOCK_EXCLUSIVE);
645645
LockBuffer(buffer,BUFFER_LOCK_EXCLUSIVE);
646+
}
646647

647-
/*
648-
* Because the buffers were unlocked for a while, it's possible,
649-
* although unlikely, that an all-visible flag became set or that
650-
* somebody used up the available space in the new page. We can
651-
*useGetVisibilityMapPins to deal with the first case. In the
652-
* second case, just retry from start.
653-
*/
654-
GetVisibilityMapPins(relation,otherBuffer,buffer,
655-
otherBlock,targetBlock,vmbuffer_other,
656-
vmbuffer);
648+
/*
649+
* Because the buffers were unlocked for a while, it's possible,
650+
* although unlikely, that an all-visible flag became set or that
651+
* somebody used up the available space in the new page. We can use
652+
* GetVisibilityMapPins to deal with the first case. In the second
653+
* case, just retry from start.
654+
*/
655+
GetVisibilityMapPins(relation,otherBuffer,buffer,
656+
otherBlock,targetBlock,vmbuffer_other,
657+
vmbuffer);
657658

658-
if (len>PageGetHeapFreeSpace(page))
659-
{
660-
LockBuffer(otherBuffer,BUFFER_LOCK_UNLOCK);
661-
UnlockReleaseBuffer(buffer);
659+
/*
660+
* Note that we have to check the available space even if our
661+
* conditional lock succeeded, because GetVisibilityMapPins might've
662+
* transiently released lock on the target buffer to acquire a VM pin
663+
* for the otherBuffer.
664+
*/
665+
if (len>PageGetHeapFreeSpace(page))
666+
{
667+
LockBuffer(otherBuffer,BUFFER_LOCK_UNLOCK);
668+
UnlockReleaseBuffer(buffer);
662669

663-
gotoloop;
664-
}
670+
gotoloop;
665671
}
666672
}
667-
668-
if (len>PageGetHeapFreeSpace(page))
673+
elseif (len>PageGetHeapFreeSpace(page))
669674
{
670675
/* We should not get here given the test at the top */
671676
elog(PANIC,"tuple is too big: size %zu",len);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp