Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ac1ae9f

Browse files
committed
Improve a number of elog messages for not-supposed-to-happen cases in btrees,
since these seem to happen after all in corrupted indexes. Make sure we supply the index name in all cases, and provide relevant block numbers where available. Also consistently identify the index name as such. Back-patch to 8.2, in hopes that this might help Mason Hale figure out his problem.
1 parent 4944852 commit ac1ae9f

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

src/backend/access/nbtree/nbtinsert.c

+22-11
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.162 2007/11/16 19:53:50 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.163 2007/12/31 04:52:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -338,7 +338,7 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
338338
if (!P_IGNORE(opaque))
339339
break;
340340
if (P_RIGHTMOST(opaque))
341-
elog(ERROR, "fell off the end of \"%s\"",
341+
elog(ERROR, "fell off the end of index \"%s\"",
342342
RelationGetRelationName(rel));
343343
}
344344
maxoff = PageGetMaxOffsetNumber(page);
@@ -492,7 +492,7 @@ _bt_findinsertloc(Relation rel,
492492
if (!P_IGNORE(lpageop))
493493
break;
494494
if (P_RIGHTMOST(lpageop))
495-
elog(ERROR, "fell off the end of \"%s\"",
495+
elog(ERROR, "fell off the end of index \"%s\"",
496496
RelationGetRelationName(rel));
497497
}
498498
_bt_relbuf(rel, buf);
@@ -840,7 +840,9 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
840840
item = (IndexTuple) PageGetItem(origpage, itemid);
841841
if (PageAddItem(rightpage, (Item) item, itemsz, rightoff,
842842
false, false) == InvalidOffsetNumber)
843-
elog(PANIC, "failed to add hikey to the right sibling");
843+
elog(PANIC, "failed to add hikey to the right sibling"
844+
" while splitting block %u of index \"%s\"",
845+
BufferGetBlockNumber(buf), RelationGetRelationName(rel));
844846
rightoff = OffsetNumberNext(rightoff);
845847
}
846848

@@ -865,7 +867,9 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
865867
}
866868
if (PageAddItem(leftpage, (Item) item, itemsz, leftoff,
867869
false, false) == InvalidOffsetNumber)
868-
elog(PANIC, "failed to add hikey to the left sibling");
870+
elog(PANIC, "failed to add hikey to the left sibling"
871+
" while splitting block %u of index \"%s\"",
872+
BufferGetBlockNumber(buf), RelationGetRelationName(rel));
869873
leftoff = OffsetNumberNext(leftoff);
870874

871875
/*
@@ -942,7 +946,10 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
942946
spage = BufferGetPage(sbuf);
943947
sopaque = (BTPageOpaque) PageGetSpecialPointer(spage);
944948
if (sopaque->btpo_prev != ropaque->btpo_prev)
945-
elog(PANIC, "right sibling's left-link doesn't match");
949+
elog(PANIC, "right sibling's left-link doesn't match: "
950+
"block %u links to %u instead of expected %u in index \"%s\"",
951+
ropaque->btpo_next, sopaque->btpo_prev, ropaque->btpo_prev,
952+
RelationGetRelationName(rel));
946953

947954
/*
948955
* Check to see if we can set the SPLIT_END flag in the right-hand
@@ -1305,7 +1312,7 @@ _bt_findsplitloc(Relation rel,
13051312
* in case ...
13061313
*/
13071314
if (!state.have_split)
1308-
elog(ERROR, "could not find a feasible split point for \"%s\"",
1315+
elog(ERROR, "could not find a feasible split point for index \"%s\"",
13091316
RelationGetRelationName(rel));
13101317

13111318
*newitemonleft = state.newitemonleft;
@@ -1509,7 +1516,7 @@ _bt_insert_parent(Relation rel,
15091516

15101517
/* Check for error only after writing children */
15111518
if (pbuf == InvalidBuffer)
1512-
elog(ERROR, "failed to re-find parent key in \"%s\" for split pages %u/%u",
1519+
elog(ERROR, "failed to re-find parent key in index \"%s\" for split pages %u/%u",
15131520
RelationGetRelationName(rel), bknum, rbknum);
15141521

15151522
/* Recursively update the parent */
@@ -1717,7 +1724,9 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
17171724
*/
17181725
if (PageAddItem(rootpage, (Item) new_item, itemsz, P_HIKEY,
17191726
false, false) == InvalidOffsetNumber)
1720-
elog(PANIC, "failed to add leftkey to new root page");
1727+
elog(PANIC, "failed to add leftkey to new root page"
1728+
" while splitting block %u of index \"%s\"",
1729+
BufferGetBlockNumber(lbuf), RelationGetRelationName(rel));
17211730
pfree(new_item);
17221731

17231732
/*
@@ -1735,7 +1744,9 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
17351744
*/
17361745
if (PageAddItem(rootpage, (Item) new_item, itemsz, P_FIRSTKEY,
17371746
false, false) == InvalidOffsetNumber)
1738-
elog(PANIC, "failed to add rightkey to new root page");
1747+
elog(PANIC, "failed to add rightkey to new root page"
1748+
" while splitting block %u of index \"%s\"",
1749+
BufferGetBlockNumber(lbuf), RelationGetRelationName(rel));
17391750
pfree(new_item);
17401751

17411752
MarkBufferDirty(rootbuf);
@@ -1822,7 +1833,7 @@ _bt_pgaddtup(Relation rel,
18221833

18231834
if (PageAddItem(page, (Item) itup, itemsize, itup_off,
18241835
false, false) == InvalidOffsetNumber)
1825-
elog(PANIC, "failed to add item to the %s for \"%s\"",
1836+
elog(PANIC, "failed to add item to the %s in index \"%s\"",
18261837
where, RelationGetRelationName(rel));
18271838
}
18281839

src/backend/access/nbtree/nbtpage.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.104 2007/11/15 21:14:32 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.105 2007/12/31 04:52:05 tgl Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -293,14 +293,14 @@ _bt_getroot(Relation rel, int access)
293293

294294
/* it's dead, Jim. step right one page */
295295
if (P_RIGHTMOST(rootopaque))
296-
elog(ERROR, "no live root page found in \"%s\"",
296+
elog(ERROR, "no live root page found in index \"%s\"",
297297
RelationGetRelationName(rel));
298298
rootblkno = rootopaque->btpo_next;
299299
}
300300

301301
/* Note: can't check btpo.level on deleted pages */
302302
if (rootopaque->btpo.level != rootlevel)
303-
elog(ERROR, "root page %u of \"%s\" has level %u, expected %u",
303+
elog(ERROR, "root page %u of index \"%s\" has level %u, expected %u",
304304
rootblkno, RelationGetRelationName(rel),
305305
rootopaque->btpo.level, rootlevel);
306306
}
@@ -395,14 +395,14 @@ _bt_gettrueroot(Relation rel)
395395

396396
/* it's dead, Jim. step right one page */
397397
if (P_RIGHTMOST(rootopaque))
398-
elog(ERROR, "no live root page found in \"%s\"",
398+
elog(ERROR, "no live root page found in index \"%s\"",
399399
RelationGetRelationName(rel));
400400
rootblkno = rootopaque->btpo_next;
401401
}
402402

403403
/* Note: can't check btpo.level on deleted pages */
404404
if (rootopaque->btpo.level != rootlevel)
405-
elog(ERROR, "root page %u of \"%s\" has level %u, expected %u",
405+
elog(ERROR, "root page %u of index \"%s\" has level %u, expected %u",
406406
rootblkno, RelationGetRelationName(rel),
407407
rootopaque->btpo.level, rootlevel);
408408

@@ -761,7 +761,7 @@ _bt_parent_deletion_safe(Relation rel, BlockNumber target, BTStack stack)
761761
ItemPointerSet(&(stack->bts_btentry.t_tid), target, P_HIKEY);
762762
pbuf = _bt_getstackbuf(rel, stack, BT_READ);
763763
if (pbuf == InvalidBuffer)
764-
elog(ERROR, "failed to re-find parent key in \"%s\" for deletion target page %u",
764+
elog(ERROR, "failed to re-find parent key in index \"%s\" for deletion target page %u",
765765
RelationGetRelationName(rel), target);
766766
parent = stack->bts_blkno;
767767
poffset = stack->bts_offset;
@@ -1019,7 +1019,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
10191019
return 0;
10201020
}
10211021
if (opaque->btpo_prev != leftsib)
1022-
elog(ERROR, "left link changed unexpectedly in block %u of \"%s\"",
1022+
elog(ERROR, "left link changed unexpectedly in block %u of index \"%s\"",
10231023
target, RelationGetRelationName(rel));
10241024

10251025
/*
@@ -1035,7 +1035,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
10351035
ItemPointerSet(&(stack->bts_btentry.t_tid), target, P_HIKEY);
10361036
pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
10371037
if (pbuf == InvalidBuffer)
1038-
elog(ERROR, "failed to re-find parent key in \"%s\" for deletion target page %u",
1038+
elog(ERROR, "failed to re-find parent key in index \"%s\" for deletion target page %u",
10391039
RelationGetRelationName(rel), target);
10401040
parent = stack->bts_blkno;
10411041
poffset = stack->bts_offset;
@@ -1056,7 +1056,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
10561056
if (poffset == P_FIRSTDATAKEY(opaque))
10571057
parent_half_dead = true;
10581058
else
1059-
elog(ERROR, "failed to delete rightmost child %u of %u in \"%s\"",
1059+
elog(ERROR, "failed to delete rightmost child %u of block %u in index \"%s\"",
10601060
target, parent, RelationGetRelationName(rel));
10611061
}
10621062
else
@@ -1138,7 +1138,8 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
11381138
itemid = PageGetItemId(page, nextoffset);
11391139
itup = (IndexTuple) PageGetItem(page, itemid);
11401140
if (ItemPointerGetBlockNumber(&(itup->t_tid)) != rightsib)
1141-
elog(PANIC, "right sibling is not next child in \"%s\"",
1141+
elog(PANIC, "right sibling %u of block %u is not next child of %u in index \"%s\"",
1142+
rightsib, target, BufferGetBlockNumber(pbuf),
11421143
RelationGetRelationName(rel));
11431144
PageIndexTupleDelete(page, nextoffset);
11441145
}

src/backend/access/nbtree/nbtsearch.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.114 2007/11/15 21:14:32 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.115 2007/12/31 04:52:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -192,7 +192,7 @@ _bt_moveright(Relation rel,
192192
}
193193

194194
if (P_IGNORE(opaque))
195-
elog(ERROR, "fell off the end of \"%s\"",
195+
elog(ERROR, "fell off the end of index \"%s\"",
196196
RelationGetRelationName(rel));
197197

198198
return buf;
@@ -1282,7 +1282,7 @@ _bt_walk_left(Relation rel, Buffer buf)
12821282
for (;;)
12831283
{
12841284
if (P_RIGHTMOST(opaque))
1285-
elog(ERROR, "fell off the end of \"%s\"",
1285+
elog(ERROR, "fell off the end of index \"%s\"",
12861286
RelationGetRelationName(rel));
12871287
blkno = opaque->btpo_next;
12881288
buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ);
@@ -1305,8 +1305,8 @@ _bt_walk_left(Relation rel, Buffer buf)
13051305
* into an infinite loop if there's anything wrong.
13061306
*/
13071307
if (opaque->btpo_prev == lblkno)
1308-
elog(ERROR, "could not find left sibling in \"%s\"",
1309-
RelationGetRelationName(rel));
1308+
elog(ERROR, "could not find left sibling of block %u in index \"%s\"",
1309+
obknum, RelationGetRelationName(rel));
13101310
/* Okay to try again with new lblkno value */
13111311
}
13121312
}
@@ -1364,7 +1364,7 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
13641364
{
13651365
blkno = opaque->btpo_next;
13661366
if (blkno == P_NONE)
1367-
elog(ERROR, "fell off the end of \"%s\"",
1367+
elog(ERROR, "fell off the end of index \"%s\"",
13681368
RelationGetRelationName(rel));
13691369
buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ);
13701370
page = BufferGetPage(buf);
@@ -1375,7 +1375,8 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
13751375
if (opaque->btpo.level == level)
13761376
break;
13771377
if (opaque->btpo.level < level)
1378-
elog(ERROR, "btree level %u not found", level);
1378+
elog(ERROR, "btree level %u not found in index \"%s\"",
1379+
level, RelationGetRelationName(rel));
13791380

13801381
/* Descend to leftmost or rightmost child page */
13811382
if (rightmost)

0 commit comments

Comments
 (0)