1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-13 16:22:44 +03:00

Error message editing in backend/access.

This commit is contained in:
Tom Lane
2003-07-21 20:29:40 +00:00
parent c6106d91e2
commit ec7aa4b515
33 changed files with 702 additions and 533 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.100 2003/05/27 17:49:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.101 2003/07/21 20:29:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -153,7 +153,7 @@ top:
*
* Returns InvalidTransactionId if there is no conflict, else an xact ID
* we must wait for to see if it commits a conflicting tuple. If an actual
* conflict is detected, no return --- just elog().
* conflict is detected, no return --- just ereport().
*/
static TransactionId
_bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
@@ -237,8 +237,10 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
/*
* Otherwise we have a definite conflict.
*/
elog(ERROR, "Cannot insert a duplicate key into unique index %s",
RelationGetRelationName(rel));
ereport(ERROR,
(errcode(ERRCODE_UNIQUE_VIOLATION),
errmsg("duplicate key violates UNIQUE constraint \"%s\"",
RelationGetRelationName(rel))));
}
else if (htup.t_data != NULL)
{
@@ -291,7 +293,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
if (!P_IGNORE(opaque))
break;
if (P_RIGHTMOST(opaque))
elog(ERROR, "_bt_check_unique: fell off the end of %s",
elog(ERROR, "fell off the end of \"%s\"",
RelationGetRelationName(rel));
}
maxoff = PageGetMaxOffsetNumber(page);
@@ -387,8 +389,11 @@ _bt_insertonpg(Relation rel,
* itemsz doesn't include the ItemId.
*/
if (itemsz > BTMaxItemSize(page))
elog(ERROR, "btree: index item size %lu exceeds maximum %lu",
(unsigned long) itemsz, BTMaxItemSize(page));
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index tuple size %lu exceeds btree maximum, %lu",
(unsigned long) itemsz,
(unsigned long) BTMaxItemSize(page))));
/*
* Determine exactly where new item will go.
@@ -445,7 +450,7 @@ _bt_insertonpg(Relation rel,
if (!P_IGNORE(lpageop))
break;
if (P_RIGHTMOST(lpageop))
elog(ERROR, "_bt_insertonpg: fell off the end of %s",
elog(ERROR, "fell off the end of \"%s\"",
RelationGetRelationName(rel));
}
_bt_relbuf(rel, buf);
@@ -536,7 +541,7 @@ _bt_insertonpg(Relation rel,
}
}
/* Do the actual update. No elog(ERROR) until changes are logged */
/* Do the update. No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
_bt_pgaddtup(rel, page, itemsz, btitem, newitemoff, "page");
@@ -705,7 +710,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
item = (BTItem) PageGetItem(origpage, itemid);
if (PageAddItem(rightpage, (Item) item, itemsz, rightoff,
LP_USED) == InvalidOffsetNumber)
elog(PANIC, "btree: failed to add hikey to the right sibling");
elog(PANIC, "failed to add hikey to the right sibling");
rightoff = OffsetNumberNext(rightoff);
}
@@ -730,7 +735,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
}
if (PageAddItem(leftpage, (Item) item, itemsz, leftoff,
LP_USED) == InvalidOffsetNumber)
elog(PANIC, "btree: failed to add hikey to the left sibling");
elog(PANIC, "failed to add hikey to the left sibling");
leftoff = OffsetNumberNext(leftoff);
/*
@@ -815,14 +820,14 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
spage = BufferGetPage(sbuf);
sopaque = (BTPageOpaque) PageGetSpecialPointer(spage);
if (sopaque->btpo_prev != ropaque->btpo_prev)
elog(PANIC, "btree: right sibling's left-link doesn't match");
elog(PANIC, "right sibling's left-link doesn't match");
}
/*
* Right sibling is locked, new siblings are prepared, but original
* page is not updated yet. Log changes before continuing.
*
* NO ELOG(ERROR) till right sibling is updated.
* NO EREPORT(ERROR) till right sibling is updated.
*/
START_CRIT_SECTION();
@@ -1059,7 +1064,7 @@ _bt_findsplitloc(Relation rel,
* just in case ...
*/
if (!state.have_split)
elog(FATAL, "_bt_findsplitloc: can't find a feasible split point for %s",
elog(ERROR, "cannot find a feasible split point for \"%s\"",
RelationGetRelationName(rel));
*newitemonleft = state.newitemonleft;
@@ -1193,7 +1198,7 @@ _bt_insert_parent(Relation rel,
BTPageOpaque lpageop;
if (!InRecovery)
elog(DEBUG2, "_bt_insert_parent: concurrent ROOT page split");
elog(DEBUG2, "concurrent ROOT page split");
lpageop = (BTPageOpaque) PageGetSpecialPointer(page);
/* Find the leftmost page at the next level up */
pbuf = _bt_get_endpoint(rel, lpageop->btpo.level + 1, false);
@@ -1232,8 +1237,8 @@ _bt_insert_parent(Relation rel,
/* Check for error only after writing children */
if (pbuf == InvalidBuffer)
elog(ERROR, "_bt_getstackbuf: my bits moved right off the end of the world!"
"\n\tRecreate index %s.", RelationGetRelationName(rel));
elog(ERROR, "failed to re-find parent key in \"%s\"",
RelationGetRelationName(rel));
/* Recursively update the parent */
newres = _bt_insertonpg(rel, pbuf, stack->bts_parent,
@@ -1399,7 +1404,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
metapg = BufferGetPage(metabuf);
metad = BTPageGetMeta(metapg);
/* NO ELOG(ERROR) from here till newroot op is logged */
/* NO EREPORT(ERROR) from here till newroot op is logged */
START_CRIT_SECTION();
/* set btree special data */
@@ -1431,7 +1436,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
* the two items will go into positions P_HIKEY and P_FIRSTKEY.
*/
if (PageAddItem(rootpage, (Item) new_item, itemsz, P_HIKEY, LP_USED) == InvalidOffsetNumber)
elog(PANIC, "btree: failed to add leftkey to new root page");
elog(PANIC, "failed to add leftkey to new root page");
pfree(new_item);
/*
@@ -1448,7 +1453,7 @@ _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, "btree: failed to add rightkey to new root page");
elog(PANIC, "failed to add rightkey to new root page");
pfree(new_item);
/* XLOG stuff */
@@ -1533,7 +1538,7 @@ _bt_pgaddtup(Relation rel,
if (PageAddItem(page, (Item) btitem, itemsize, itup_off,
LP_USED) == InvalidOffsetNumber)
elog(PANIC, "btree: failed to add item to the %s for %s",
elog(PANIC, "failed to add item to the %s for \"%s\"",
where, RelationGetRelationName(rel));
}

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.65 2003/05/27 17:49:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.66 2003/07/21 20:29:39 tgl Exp $
*
* NOTES
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -44,7 +44,7 @@ _bt_metapinit(Relation rel)
BTPageOpaque op;
if (RelationGetNumberOfBlocks(rel) != 0)
elog(ERROR, "Cannot initialize non-empty btree %s",
elog(ERROR, "cannot initialize non-empty btree index \"%s\"",
RelationGetRelationName(rel));
buf = ReadBuffer(rel, P_NEW);
@@ -145,13 +145,17 @@ _bt_getroot(Relation rel, int access)
/* sanity-check the metapage */
if (!(metaopaque->btpo_flags & BTP_META) ||
metad->btm_magic != BTREE_MAGIC)
elog(ERROR, "Index %s is not a btree",
RelationGetRelationName(rel));
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" is not a btree",
RelationGetRelationName(rel))));
if (metad->btm_version != BTREE_VERSION)
elog(ERROR, "Version mismatch on %s: version %d file, version %d code",
RelationGetRelationName(rel),
metad->btm_version, BTREE_VERSION);
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("version mismatch in \"%s\": file version %d, code version %d",
RelationGetRelationName(rel),
metad->btm_version, BTREE_VERSION)));
/* if no root page initialized yet, do it */
if (metad->btm_root == P_NONE)
@@ -265,7 +269,7 @@ _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 \"%s\"",
RelationGetRelationName(rel));
rootblkno = rootopaque->btpo_next;
@@ -274,7 +278,7 @@ _bt_getroot(Relation rel, int access)
/* 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 \"%s\" has level %u, expected %u",
rootblkno, RelationGetRelationName(rel),
rootopaque->btpo.level, rootlevel);
}
@@ -320,13 +324,17 @@ _bt_gettrueroot(Relation rel)
if (!(metaopaque->btpo_flags & BTP_META) ||
metad->btm_magic != BTREE_MAGIC)
elog(ERROR, "Index %s is not a btree",
RelationGetRelationName(rel));
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("index \"%s\" is not a btree",
RelationGetRelationName(rel))));
if (metad->btm_version != BTREE_VERSION)
elog(ERROR, "Version mismatch on %s: version %d file, version %d code",
RelationGetRelationName(rel),
metad->btm_version, BTREE_VERSION);
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("version mismatch in \"%s\": file version %d, code version %d",
RelationGetRelationName(rel),
metad->btm_version, BTREE_VERSION)));
/* if no root page initialized yet, fail */
if (metad->btm_root == P_NONE)
@@ -351,7 +359,7 @@ _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 \"%s\"",
RelationGetRelationName(rel));
rootblkno = rootopaque->btpo_next;
@@ -360,7 +368,7 @@ _bt_gettrueroot(Relation rel)
/* 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 \"%s\" has level %u, expected %u",
rootblkno, RelationGetRelationName(rel),
rootopaque->btpo.level, rootlevel);
@@ -416,7 +424,7 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access)
_bt_pageinit(page, BufferGetPageSize(buf));
return buf;
}
elog(DEBUG2, "_bt_getbuf: FSM returned nonrecyclable page");
elog(DEBUG2, "FSM returned nonrecyclable page");
_bt_relbuf(rel, buf);
}
@@ -630,7 +638,7 @@ _bt_delitems(Relation rel, Buffer buf,
Page page = BufferGetPage(buf);
int i;
/* No elog(ERROR) until changes are logged */
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
/*
@@ -775,7 +783,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
for (;;)
{
if (stack == NULL)
elog(ERROR, "_bt_pagedel: not enough stack items");
elog(ERROR, "not enough stack items");
if (ilevel == targetlevel)
break;
stack = stack->bts_parent;
@@ -805,7 +813,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
_bt_relbuf(rel, lbuf);
if (leftsib == P_NONE)
{
elog(LOG, "_bt_pagedel: no left sibling (concurrent deletion?)");
elog(LOG, "no left sibling (concurrent deletion?)");
return 0;
}
lbuf = _bt_getbuf(rel, leftsib, BT_WRITE);
@@ -837,7 +845,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
return 0;
}
if (opaque->btpo_prev != leftsib)
elog(ERROR, "_bt_pagedel: left link changed unexpectedly");
elog(ERROR, "left link changed unexpectedly");
/*
* And next write-lock the (current) right sibling.
*/
@@ -851,8 +859,8 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
target, P_HIKEY);
pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
if (pbuf == InvalidBuffer)
elog(ERROR, "_bt_getstackbuf: my bits moved right off the end of the world!"
"\n\tRecreate index %s.", RelationGetRelationName(rel));
elog(ERROR, "failed to re-find parent key in \"%s\"",
RelationGetRelationName(rel));
parent = stack->bts_blkno;
poffset = stack->bts_offset;
/*
@@ -924,7 +932,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
* Here we begin doing the deletion.
*/
/* No elog(ERROR) until changes are logged */
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
/*
@@ -954,7 +962,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
itemid = PageGetItemId(page, nextoffset);
btitem = (BTItem) PageGetItem(page, itemid);
if (ItemPointerGetBlockNumber(&(btitem->bti_itup.t_tid)) != rightsib)
elog(PANIC, "_bt_pagedel: right sibling is not next child");
elog(PANIC, "right sibling is not next child");
PageIndexTupleDelete(page, nextoffset);
}

View File

@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.102 2003/03/23 23:01:03 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.103 2003/07/21 20:29:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -108,7 +108,7 @@ btbuild(PG_FUNCTION_ARGS)
* that's not the case, big trouble's what we have.
*/
if (RelationGetNumberOfBlocks(index) != 0)
elog(ERROR, "%s already contains data",
elog(ERROR, "index \"%s\" already contains data",
RelationGetRelationName(index));
/* initialize the btree index metadata page */
@@ -816,8 +816,7 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
*/
i = FlushRelationBuffers(rel, new_pages);
if (i < 0)
elog(ERROR, "btvacuumcleanup: FlushRelationBuffers returned %d",
i);
elog(ERROR, "FlushRelationBuffers returned %d", i);
/*
* Do the physical truncation.
@@ -929,8 +928,8 @@ _bt_restscan(IndexScanDesc scan)
* we can find it again.
*/
if (P_RIGHTMOST(opaque))
elog(ERROR, "_bt_restscan: my bits moved right off the end of the world!"
"\n\tRecreate index %s.", RelationGetRelationName(rel));
elog(ERROR, "failed to re-find previous key in \"%s\"",
RelationGetRelationName(rel));
/* Advance to next non-dead page --- there must be one */
nextbuf = InvalidBuffer;
for (;;)
@@ -944,7 +943,7 @@ _bt_restscan(IndexScanDesc scan)
if (!P_IGNORE(opaque))
break;
if (P_RIGHTMOST(opaque))
elog(ERROR, "_bt_restscan: fell off the end of %s",
elog(ERROR, "fell off the end of \"%s\"",
RelationGetRelationName(rel));
}
_bt_relbuf(rel, buf);

View File

@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.74 2003/02/22 00:45:04 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.75 2003/07/21 20:29:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -168,7 +168,7 @@ _bt_moveright(Relation rel,
}
if (P_IGNORE(opaque))
elog(ERROR, "_bt_moveright: fell off the end of %s",
elog(ERROR, "fell off the end of \"%s\"",
RelationGetRelationName(rel));
return buf;
@@ -552,7 +552,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
{
pfree(nKeyIs);
pfree(scankeys);
elog(ERROR, "_bt_first: btree doesn't support is(not)null, yet");
elog(ERROR, "btree doesn't support is(not)null, yet");
return false;
}
procinfo = index_getprocinfo(rel, i + 1, BTORDER_PROC);
@@ -700,7 +700,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
result = _bt_compare(rel, keysCount, scankeys, page, offnum);
} while (result == 0);
if (!_bt_step(scan, &buf, BackwardScanDirection))
elog(ERROR, "_bt_first: equal items disappeared?");
elog(ERROR, "equal items disappeared?");
}
break;
@@ -991,7 +991,7 @@ _bt_walk_left(Relation rel, Buffer buf)
for (;;)
{
if (P_RIGHTMOST(opaque))
elog(ERROR, "_bt_walk_left: fell off the end of %s",
elog(ERROR, "fell off the end of \"%s\"",
RelationGetRelationName(rel));
blkno = opaque->btpo_next;
_bt_relbuf(rel, buf);
@@ -1015,7 +1015,7 @@ _bt_walk_left(Relation rel, Buffer buf)
* if there's anything wrong.
*/
if (opaque->btpo_prev == lblkno)
elog(ERROR, "_bt_walk_left: can't find left sibling in %s",
elog(ERROR, "cannot find left sibling in \"%s\"",
RelationGetRelationName(rel));
/* Okay to try again with new lblkno value */
}
@@ -1028,7 +1028,7 @@ _bt_walk_left(Relation rel, Buffer buf)
* _bt_get_endpoint() -- Find the first or last page on a given tree level
*
* If the index is empty, we will return InvalidBuffer; any other failure
* condition causes elog(). We will not return a dead page.
* condition causes ereport(). We will not return a dead page.
*
* The returned buffer is pinned and read-locked.
*/
@@ -1075,7 +1075,7 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
{
blkno = opaque->btpo_next;
if (blkno == P_NONE)
elog(ERROR, "_bt_get_endpoint: fell off the end of %s",
elog(ERROR, "fell off the end of \"%s\"",
RelationGetRelationName(rel));
_bt_relbuf(rel, buf);
buf = _bt_getbuf(rel, blkno, BT_READ);
@@ -1087,7 +1087,7 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
if (opaque->btpo.level == level)
break;
if (opaque->btpo.level < level)
elog(ERROR, "_bt_get_endpoint: btree level %u not found", level);
elog(ERROR, "btree level %u not found", level);
/* Descend to leftmost or rightmost child page */
if (rightmost)
@@ -1176,7 +1176,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
}
else
{
elog(ERROR, "Illegal scan direction %d", dir);
elog(ERROR, "invalid scan direction: %d", (int) dir);
start = 0; /* keep compiler quiet */
}

View File

@@ -36,7 +36,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.72 2003/02/22 00:45:04 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.73 2003/07/21 20:29:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -332,7 +332,7 @@ _bt_sortaddtup(Page page,
if (PageAddItem(page, (Item) btitem, itemsize, itup_off,
LP_USED) == InvalidOffsetNumber)
elog(ERROR, "btree: failed to add item to the page in _bt_sort");
elog(ERROR, "failed to add item to the index page");
}
/*----------
@@ -397,8 +397,11 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
* during creation of an index, we don't go through there.
*/
if (btisz > BTMaxItemSize(npage))
elog(ERROR, "btree: index item size %lu exceeds maximum %ld",
(unsigned long) btisz, BTMaxItemSize(npage));
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index tuple size %lu exceeds btree maximum, %lu",
(unsigned long) btisz,
(unsigned long) BTMaxItemSize(npage))));
if (pgspc < btisz || pgspc < state->btps_full)
{

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.51 2002/09/04 20:31:12 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.52 2003/07/21 20:29:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -227,7 +227,7 @@ _bt_orderkeys(IndexScanDesc scan)
cur = &key[0];
/* check input keys are correctly ordered */
if (cur->sk_attno != 1)
elog(ERROR, "_bt_orderkeys: key(s) for attribute 1 missed");
elog(ERROR, "key(s) for attribute 1 missed");
/* We can short-circuit most of the work if there's just one key */
if (numberOfKeys == 1)
@@ -305,8 +305,7 @@ _bt_orderkeys(IndexScanDesc scan)
/* check input keys are correctly ordered */
if (i < numberOfKeys && cur->sk_attno != attno + 1)
elog(ERROR, "_bt_orderkeys: key(s) for attribute %d missed",
attno + 1);
elog(ERROR, "key(s) for attribute %d missed", attno + 1);
/*
* If = has been specified, no other key will be used. In case
@@ -462,8 +461,7 @@ _bt_getstrategynumber(RegProcedure sk_procedure, StrategyMap map)
if (sk_procedure == map->entry[j].sk_procedure)
return j;
}
elog(ERROR, "_bt_getstrategynumber: unable to identify operator %u",
sk_procedure);
elog(ERROR, "unable to identify operator %u", sk_procedure);
return -1; /* keep compiler quiet */
}