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

Commit70ce5c9

Browse files
committed
Fix "failed to re-find parent key" btree VACUUM failure by revising page
deletion code to avoid the case where an upper-level btree page remains "halfdead" for a significant period of time, and to block insertions into a keyrange that is in process of being re-assigned to the right sibling of thedeleted page's parent. This prevents the scenario reported by Ed L. whereinindex keys could become out-of-order in the grandparent index level.Since this is a moderately invasive fix, I'm applying it only to HEAD.The bug exists back to 7.4, but the back branches will get a different patch.
1 parent19d0c46 commit70ce5c9

File tree

6 files changed

+363
-139
lines changed

6 files changed

+363
-139
lines changed

‎src/backend/access/nbtree/README

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/src/backend/access/nbtree/README,v 1.13 2006/07/25 19:13:00 tgl Exp $
1+
$PostgreSQL: pgsql/src/backend/access/nbtree/README,v 1.14 2006/11/01 19:43:17 tgl Exp $
22

33
This directory contains a correct implementation of Lehman and Yao's
44
high-concurrency B-tree management algorithm (P. Lehman and S. Yao,
@@ -201,26 +201,25 @@ When we delete the last remaining child of a parent page, we mark the
201201
parent page "half-dead" as part of the atomic update that deletes the
202202
child page. This implicitly transfers the parent's key space to its right
203203
sibling (which it must have, since we never delete the overall-rightmost
204-
page of a level). No future insertions into the parent level are allowed
205-
to insert keys into the half-dead page --- they must move right to its
206-
sibling, instead. The parent remains empty and can be deleted in a
207-
separate atomic action. (However, if it's the rightmost child of its own
208-
parent, it might have to stay half-dead for awhile, until it's also the
209-
only child.)
210-
211-
Note that an empty leaf page is a valid tree state, but an empty interior
212-
page is not legal (an interior page must have children to delegate its
213-
key space to). So an interior page *must* be marked half-dead as soon
214-
as its last child is deleted.
204+
page of a level). Searches ignore the half-dead page and immediately move
205+
right. We need not worry about insertions into a half-dead page --- insertions
206+
into upper tree levels happen only as a result of splits of child pages, and
207+
the half-dead page no longer has any children that could split. Therefore
208+
the page stays empty even when we don't have lock on it, and we can complete
209+
its deletion in a second atomic action.
215210

216211
The notion of a half-dead page means that the key space relationship between
217212
the half-dead page's level and its parent's level may be a little out of
218213
whack: key space that appears to belong to the half-dead page's parent on the
219-
parent level may really belong to its right sibling. We can tolerate this,
220-
however, because insertions and deletions on upper tree levels are always
221-
done by reference to child page numbers, not keys. The only cost is that
222-
searches may sometimes descend to the half-dead page and then have to move
223-
right, rather than going directly to the sibling page.
214+
parent level may really belong to its right sibling. To prevent any possible
215+
problems, we hold lock on the deleted child page until we have finished
216+
deleting any now-half-dead parent page(s). This prevents any insertions into
217+
the transferred keyspace until the operation is complete. The reason for
218+
doing this is that a sufficiently large number of insertions into the
219+
transferred keyspace, resulting in multiple page splits, could propagate keys
220+
from that keyspace into the parent level, resulting in transiently
221+
out-of-order keys in that level. It is thought that that wouldn't cause any
222+
serious problem, but it seems too risky to allow.
224223

225224
A deleted page cannot be reclaimed immediately, since there may be other
226225
processes waiting to reference it (ie, search processes that just left the

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.144 2006/10/04 00:29:48 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.145 2006/11/01 19:43:17 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1337,8 +1337,8 @@ _bt_insert_parent(Relation rel,
13371337

13381338
/* Check for error only after writing children */
13391339
if (pbuf==InvalidBuffer)
1340-
elog(ERROR,"failed to re-find parent key in \"%s\"",
1341-
RelationGetRelationName(rel));
1340+
elog(ERROR,"failed to re-find parent key in \"%s\" for split pages %u/%u",
1341+
RelationGetRelationName(rel),bknum,rbknum);
13421342

13431343
/* Recursively update the parent */
13441344
_bt_insertonpg(rel,pbuf,stack->bts_parent,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp