]> granicus.if.org Git - postgresql/commitdiff
Improve a number of elog messages for not-supposed-to-happen cases in btrees,
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 31 Dec 2007 04:52:20 +0000 (04:52 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 31 Dec 2007 04:52:20 +0000 (04:52 +0000)
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.

src/backend/access/nbtree/nbtinsert.c
src/backend/access/nbtree/nbtpage.c
src/backend/access/nbtree/nbtsearch.c

index beb543f0939d2250603d5a4bd111dc747d004afa..cc85592b1836c9564b24b1662b039bcb8cbc4989 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.146.2.1 2007/01/27 20:53:36 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.146.2.2 2007/12/31 04:52:20 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -324,7 +324,7 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
                                if (!P_IGNORE(opaque))
                                        break;
                                if (P_RIGHTMOST(opaque))
-                                       elog(ERROR, "fell off the end of \"%s\"",
+                                       elog(ERROR, "fell off the end of index \"%s\"",
                                                 RelationGetRelationName(rel));
                        }
                        maxoff = PageGetMaxOffsetNumber(page);
@@ -496,7 +496,7 @@ _bt_insertonpg(Relation rel,
                                if (!P_IGNORE(lpageop))
                                        break;
                                if (P_RIGHTMOST(lpageop))
-                                       elog(ERROR, "fell off the end of \"%s\"",
+                                       elog(ERROR, "fell off the end of index \"%s\"",
                                                 RelationGetRelationName(rel));
                        }
                        _bt_relbuf(rel, buf);
@@ -777,7 +777,9 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
                item = (IndexTuple) PageGetItem(origpage, itemid);
                if (PageAddItem(rightpage, (Item) item, itemsz, rightoff,
                                                LP_USED) == InvalidOffsetNumber)
-                       elog(PANIC, "failed to add hikey to the right sibling");
+                       elog(PANIC, "failed to add hikey to the right sibling"
+                                " while splitting block %u of index \"%s\"",
+                                BufferGetBlockNumber(buf), RelationGetRelationName(rel));
                rightoff = OffsetNumberNext(rightoff);
        }
 
@@ -802,7 +804,9 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
        }
        if (PageAddItem(leftpage, (Item) item, itemsz, leftoff,
                                        LP_USED) == InvalidOffsetNumber)
-               elog(PANIC, "failed to add hikey to the left sibling");
+               elog(PANIC, "failed to add hikey to the left sibling"
+                        " while splitting block %u of index \"%s\"",
+                        BufferGetBlockNumber(buf), RelationGetRelationName(rel));
        leftoff = OffsetNumberNext(leftoff);
 
        /*
@@ -887,7 +891,10 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
                spage = BufferGetPage(sbuf);
                sopaque = (BTPageOpaque) PageGetSpecialPointer(spage);
                if (sopaque->btpo_prev != ropaque->btpo_prev)
-                       elog(PANIC, "right sibling's left-link doesn't match");
+                       elog(PANIC, "right sibling's left-link doesn't match: "
+                                "block %u links to %u instead of expected %u in index \"%s\"",
+                                ropaque->btpo_next, sopaque->btpo_prev, ropaque->btpo_prev,
+                                RelationGetRelationName(rel));
 
                /*
                 * Check to see if we can set the SPLIT_END flag in the right-hand
@@ -1175,7 +1182,7 @@ _bt_findsplitloc(Relation rel,
         * in case ...
         */
        if (!state.have_split)
-               elog(ERROR, "could not find a feasible split point for \"%s\"",
+               elog(ERROR, "could not find a feasible split point for index \"%s\"",
                         RelationGetRelationName(rel));
 
        *newitemonleft = state.newitemonleft;
@@ -1345,7 +1352,7 @@ _bt_insert_parent(Relation rel,
 
                /* Check for error only after writing children */
                if (pbuf == InvalidBuffer)
-                       elog(ERROR, "failed to re-find parent key in \"%s\" for split pages %u/%u",
+                       elog(ERROR, "failed to re-find parent key in index \"%s\" for split pages %u/%u",
                                 RelationGetRelationName(rel), bknum, rbknum);
 
                /* Recursively update the parent */
@@ -1552,7 +1559,9 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
         * benefit of _bt_restore_page().
         */
        if (PageAddItem(rootpage, (Item) new_item, itemsz, P_HIKEY, LP_USED) == InvalidOffsetNumber)
-               elog(PANIC, "failed to add leftkey to new root page");
+               elog(PANIC, "failed to add leftkey to new root page"
+                        " while splitting block %u of index \"%s\"",
+                        BufferGetBlockNumber(lbuf), RelationGetRelationName(rel));
        pfree(new_item);
 
        /*
@@ -1569,7 +1578,9 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
         * insert the right page pointer into the new root page.
         */
        if (PageAddItem(rootpage, (Item) new_item, itemsz, P_FIRSTKEY, LP_USED) == InvalidOffsetNumber)
-               elog(PANIC, "failed to add rightkey to new root page");
+               elog(PANIC, "failed to add rightkey to new root page"
+                        " while splitting block %u of index \"%s\"",
+                        BufferGetBlockNumber(lbuf), RelationGetRelationName(rel));
        pfree(new_item);
 
        MarkBufferDirty(rootbuf);
@@ -1656,7 +1667,7 @@ _bt_pgaddtup(Relation rel,
 
        if (PageAddItem(page, (Item) itup, itemsize, itup_off,
                                        LP_USED) == InvalidOffsetNumber)
-               elog(PANIC, "failed to add item to the %s for \"%s\"",
+               elog(PANIC, "failed to add item to the %s in index \"%s\"",
                         where, RelationGetRelationName(rel));
 }
 
index 1db8d8b456cacecc4e3f9db95a211b920eeba57b..6bf5fb70588503cdf7c3b201044856c40c7d9498 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.101 2006/11/01 19:43:17 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.101.2.1 2007/12/31 04:52:20 tgl Exp $
  *
  *     NOTES
  *        Postgres btree pages look like ordinary relation pages.      The opaque
@@ -293,14 +293,14 @@ _bt_getroot(Relation rel, int access)
 
                        /* it's dead, Jim.  step right one page */
                        if (P_RIGHTMOST(rootopaque))
-                               elog(ERROR, "no live root page found in \"%s\"",
+                               elog(ERROR, "no live root page found in index \"%s\"",
                                         RelationGetRelationName(rel));
                        rootblkno = rootopaque->btpo_next;
                }
 
                /* Note: can't check btpo.level on deleted pages */
                if (rootopaque->btpo.level != rootlevel)
-                       elog(ERROR, "root page %u of \"%s\" has level %u, expected %u",
+                       elog(ERROR, "root page %u of index \"%s\" has level %u, expected %u",
                                 rootblkno, RelationGetRelationName(rel),
                                 rootopaque->btpo.level, rootlevel);
        }
@@ -395,14 +395,14 @@ _bt_gettrueroot(Relation rel)
 
                /* it's dead, Jim.  step right one page */
                if (P_RIGHTMOST(rootopaque))
-                       elog(ERROR, "no live root page found in \"%s\"",
+                       elog(ERROR, "no live root page found in index \"%s\"",
                                 RelationGetRelationName(rel));
                rootblkno = rootopaque->btpo_next;
        }
 
        /* Note: can't check btpo.level on deleted pages */
        if (rootopaque->btpo.level != rootlevel)
-               elog(ERROR, "root page %u of \"%s\" has level %u, expected %u",
+               elog(ERROR, "root page %u of index \"%s\" has level %u, expected %u",
                         rootblkno, RelationGetRelationName(rel),
                         rootopaque->btpo.level, rootlevel);
 
@@ -761,7 +761,7 @@ _bt_parent_deletion_safe(Relation rel, BlockNumber target, BTStack stack)
        ItemPointerSet(&(stack->bts_btentry.t_tid), target, P_HIKEY);
        pbuf = _bt_getstackbuf(rel, stack, BT_READ);
        if (pbuf == InvalidBuffer)
-               elog(ERROR, "failed to re-find parent key in \"%s\" for deletion target page %u",
+               elog(ERROR, "failed to re-find parent key in index \"%s\" for deletion target page %u",
                         RelationGetRelationName(rel), target);
        parent = stack->bts_blkno;
        poffset = stack->bts_offset;
@@ -1019,7 +1019,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
                return 0;
        }
        if (opaque->btpo_prev != leftsib)
-               elog(ERROR, "left link changed unexpectedly in block %u of \"%s\"",
+               elog(ERROR, "left link changed unexpectedly in block %u of index \"%s\"",
                         target, RelationGetRelationName(rel));
 
        /*
@@ -1035,7 +1035,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
        ItemPointerSet(&(stack->bts_btentry.t_tid), target, P_HIKEY);
        pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
        if (pbuf == InvalidBuffer)
-               elog(ERROR, "failed to re-find parent key in \"%s\" for deletion target page %u",
+               elog(ERROR, "failed to re-find parent key in index \"%s\" for deletion target page %u",
                         RelationGetRelationName(rel), target);
        parent = stack->bts_blkno;
        poffset = stack->bts_offset;
@@ -1056,7 +1056,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
                if (poffset == P_FIRSTDATAKEY(opaque))
                        parent_half_dead = true;
                else
-                       elog(ERROR, "failed to delete rightmost child %u of %u in \"%s\"",
+                       elog(ERROR, "failed to delete rightmost child %u of block %u in index \"%s\"",
                                 target, parent, RelationGetRelationName(rel));
        }
        else
@@ -1138,7 +1138,8 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack, bool vacuum_full)
                itemid = PageGetItemId(page, nextoffset);
                itup = (IndexTuple) PageGetItem(page, itemid);
                if (ItemPointerGetBlockNumber(&(itup->t_tid)) != rightsib)
-                       elog(PANIC, "right sibling is not next child in \"%s\"",
+                       elog(PANIC, "right sibling %u of block %u is not next child of %u in index \"%s\"",
+                                rightsib, target, BufferGetBlockNumber(pbuf),
                                 RelationGetRelationName(rel));
                PageIndexTupleDelete(page, nextoffset);
        }
index 23b1a0027e9987713acdaa92ff4adaba9ff8dd03..ce18b50aa3269c4f6f60d127caee73090bef4321 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.107.2.1 2007/01/07 01:56:24 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.107.2.2 2007/12/31 04:52:20 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -192,7 +192,7 @@ _bt_moveright(Relation rel,
        }
 
        if (P_IGNORE(opaque))
-               elog(ERROR, "fell off the end of \"%s\"",
+               elog(ERROR, "fell off the end of index \"%s\"",
                         RelationGetRelationName(rel));
 
        return buf;
@@ -1268,7 +1268,7 @@ _bt_walk_left(Relation rel, Buffer buf)
                        for (;;)
                        {
                                if (P_RIGHTMOST(opaque))
-                                       elog(ERROR, "fell off the end of \"%s\"",
+                                       elog(ERROR, "fell off the end of index \"%s\"",
                                                 RelationGetRelationName(rel));
                                blkno = opaque->btpo_next;
                                buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ);
@@ -1291,8 +1291,8 @@ _bt_walk_left(Relation rel, Buffer buf)
                         * into an infinite loop if there's anything wrong.
                         */
                        if (opaque->btpo_prev == lblkno)
-                               elog(ERROR, "could not find left sibling in \"%s\"",
-                                        RelationGetRelationName(rel));
+                               elog(ERROR, "could not find left sibling of block %u in index \"%s\"",
+                                        obknum, RelationGetRelationName(rel));
                        /* Okay to try again with new lblkno value */
                }
        }
@@ -1350,7 +1350,7 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
                {
                        blkno = opaque->btpo_next;
                        if (blkno == P_NONE)
-                               elog(ERROR, "fell off the end of \"%s\"",
+                               elog(ERROR, "fell off the end of index \"%s\"",
                                         RelationGetRelationName(rel));
                        buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ);
                        page = BufferGetPage(buf);
@@ -1361,7 +1361,8 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
                if (opaque->btpo.level == level)
                        break;
                if (opaque->btpo.level < level)
-                       elog(ERROR, "btree level %u not found", level);
+                       elog(ERROR, "btree level %u not found in index \"%s\"",
+                                level, RelationGetRelationName(rel));
 
                /* Descend to leftmost or rightmost child page */
                if (rightmost)