mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-05 09:16:51 +02:00
nbtree VACUUM: cope with right sibling link corruption.
Avoid "right sibling's left-link doesn't match" errors when vacuuming a corrupt nbtree index. Just LOG the issue and press on. That way VACUUM will have a decent chance of finishing off all required processing for the index (and for the table as a whole). This error was seen in the field from time to time (it's more than a theoretical risk), so giving VACUUM the ability to press on like this has real value. Nothing short of a REINDEX is expected to fix the underlying index corruption, so giving up (by throwing an error) risks making a bad situation far worse. Anything that blocks forward progress by VACUUM like this might go unnoticed for a long time. This could eventually lead to a wraparound/xidStopLimit outage. Note that _bt_unlink_halfdead_page() has always been able to bail on page deletion when the target page's left sibling page was in an inconsistent state. It now does the same thing (returns false to back out of the second phase of deletion) when it notices sibling link corruption in the target page's right sibling page. This is similar to the work from commit5b861baa
(later backpatched as commit43e409ce
), which taught nbtree to press on with vacuuming an index when page deletion fails to "re-find" a downlink in the target page's parent page. The "re-find" check seems to make VACUUM bail on page deletion more often in practice, but there is no reason to take any chances here. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://postgr.es/m/CAH2-Wzko2q2kP1+UvgJyP9g0mF4hopK0NtQZcxwvMv9_ytGhkQ@mail.gmail.com Backpatch: 11- (all supported versions).
This commit is contained in:
parent
ff77d8687f
commit
188dad680e
@ -1912,13 +1912,6 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
|
|||||||
leftsib = opaque->btpo_next;
|
leftsib = opaque->btpo_next;
|
||||||
_bt_relbuf(rel, lbuf);
|
_bt_relbuf(rel, lbuf);
|
||||||
|
|
||||||
/*
|
|
||||||
* It'd be good to check for interrupts here, but it's not easy to
|
|
||||||
* do so because a lock is always held. This block isn't
|
|
||||||
* frequently reached, so hopefully the consequences of not
|
|
||||||
* checking interrupts aren't too bad.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (leftsib == P_NONE)
|
if (leftsib == P_NONE)
|
||||||
{
|
{
|
||||||
elog(LOG, "no left sibling (concurrent deletion?) of block %u in \"%s\"",
|
elog(LOG, "no left sibling (concurrent deletion?) of block %u in \"%s\"",
|
||||||
@ -1937,6 +1930,9 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
lbuf = _bt_getbuf(rel, leftsib, BT_WRITE);
|
lbuf = _bt_getbuf(rel, leftsib, BT_WRITE);
|
||||||
page = BufferGetPage(lbuf);
|
page = BufferGetPage(lbuf);
|
||||||
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||||
@ -1997,11 +1993,40 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
|
|||||||
rbuf = _bt_getbuf(rel, rightsib, BT_WRITE);
|
rbuf = _bt_getbuf(rel, rightsib, BT_WRITE);
|
||||||
page = BufferGetPage(rbuf);
|
page = BufferGetPage(rbuf);
|
||||||
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Validate target's right sibling page. Its left link must point back to
|
||||||
|
* the target page.
|
||||||
|
*/
|
||||||
if (opaque->btpo_prev != target)
|
if (opaque->btpo_prev != target)
|
||||||
elog(ERROR, "right sibling's left-link doesn't match: "
|
{
|
||||||
"block %u links to %u instead of expected %u in index \"%s\"",
|
/*
|
||||||
rightsib, opaque->btpo_prev, target,
|
* This is known to fail in the field; sibling link corruption is
|
||||||
RelationGetRelationName(rel));
|
* relatively common. Press on with vacuuming rather than just
|
||||||
|
* throwing an ERROR (same approach used for left-sibling's-right-link
|
||||||
|
* validation check a moment ago).
|
||||||
|
*/
|
||||||
|
ereport(LOG,
|
||||||
|
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||||
|
errmsg_internal("right sibling's left-link doesn't match: "
|
||||||
|
"right sibling %u of target %u with leafblkno %u "
|
||||||
|
"and scanblkno %u spuriously links to non-target %u "
|
||||||
|
"on level %u of index \"%s\"",
|
||||||
|
rightsib, target, leafblkno,
|
||||||
|
scanblkno, opaque->btpo_prev,
|
||||||
|
targetlevel, RelationGetRelationName(rel))));
|
||||||
|
|
||||||
|
/* Must release all pins and locks on failure exit */
|
||||||
|
if (BufferIsValid(lbuf))
|
||||||
|
_bt_relbuf(rel, lbuf);
|
||||||
|
_bt_relbuf(rel, rbuf);
|
||||||
|
_bt_relbuf(rel, buf);
|
||||||
|
if (target != leafblkno)
|
||||||
|
_bt_relbuf(rel, leafbuf);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
rightsib_is_rightmost = P_RIGHTMOST(opaque);
|
rightsib_is_rightmost = P_RIGHTMOST(opaque);
|
||||||
*rightsib_empty = (P_FIRSTDATAKEY(opaque) > PageGetMaxOffsetNumber(page));
|
*rightsib_empty = (P_FIRSTDATAKEY(opaque) > PageGetMaxOffsetNumber(page));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user