diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-24 22:04:15 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-24 22:04:15 +0000 |
| commit | cfa191f3b8115b37c526cc1eee3dd1d2af7c11ca (patch) | |
| tree | 63cd0ef3cb8c56e58fb46c0fbcf7d5738c68686e /src/backend/storage/lmgr | |
| parent | 658fca8d3abd2f8f1b04028ac2d0dd49b49896c5 (diff) | |
| download | postgresql-cfa191f3b8115b37c526cc1eee3dd1d2af7c11ca.tar.gz | |
Error message editing in backend/storage.
Diffstat (limited to 'src/backend/storage/lmgr')
| -rw-r--r-- | src/backend/storage/lmgr/deadlock.c | 42 | ||||
| -rw-r--r-- | src/backend/storage/lmgr/lmgr.c | 22 | ||||
| -rw-r--r-- | src/backend/storage/lmgr/lock.c | 56 | ||||
| -rw-r--r-- | src/backend/storage/lmgr/lwlock.c | 12 | ||||
| -rw-r--r-- | src/backend/storage/lmgr/proc.c | 31 |
5 files changed, 90 insertions, 73 deletions
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c index 37cd73eaf1..757f1df2f4 100644 --- a/src/backend/storage/lmgr/deadlock.c +++ b/src/backend/storage/lmgr/deadlock.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.20 2003/03/31 20:32:29 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.21 2003/07/24 22:04:13 tgl Exp $ * * Interface: * @@ -25,6 +25,7 @@ */ #include "postgres.h" +#include "lib/stringinfo.h" #include "miscadmin.h" #include "storage/proc.h" #include "utils/memutils.h" @@ -224,7 +225,7 @@ DeadLockCheck(PGPROC *proc) nWaitOrders = 0; if (!FindLockCycle(proc, possibleConstraints, &nSoftEdges)) - elog(FATAL, "DeadLockCheck: deadlock seems to have disappeared"); + elog(FATAL, "deadlock seems to have disappeared"); return true; /* cannot find a non-deadlocked state */ } @@ -309,7 +310,7 @@ DeadLockCheckRecurse(PGPROC *proc) { /* Regenerate the list of possible added constraints */ if (nEdges != TestConfiguration(proc)) - elog(FATAL, "DeadLockCheckRecurse: inconsistent results"); + elog(FATAL, "inconsistent results during deadlock check"); } curConstraints[nCurConstraints] = possibleConstraints[oldPossibleConstraints + i]; @@ -837,13 +838,15 @@ PrintLockQueue(LOCK *lock, const char *info) #endif /* - * Report details about a detected deadlock. + * Report a detected deadlock, with available details. */ void DeadLockReport(void) { + StringInfoData buf; int i; + initStringInfo(&buf); for (i = 0; i < nDeadlockDetails; i++) { DEADLOCK_INFO *info = &deadlockDetails[i]; @@ -855,26 +858,35 @@ DeadLockReport(void) else nextpid = deadlockDetails[0].pid; + if (i > 0) + appendStringInfoChar(&buf, '\n'); + if (info->locktag.relId == XactLockTableId && info->locktag.dbId == 0) { /* Lock is for transaction ID */ - elog(NOTICE, "Proc %d waits for %s on transaction %u; blocked by %d", - info->pid, - GetLockmodeName(info->lockmode), - info->locktag.objId.xid, - nextpid); + appendStringInfo(&buf, + gettext("Proc %d waits for %s on transaction %u; blocked by proc %d."), + info->pid, + GetLockmodeName(info->lockmode), + info->locktag.objId.xid, + nextpid); } else { /* Lock is for a relation */ - elog(NOTICE, "Proc %d waits for %s on relation %u database %u; blocked by %d", - info->pid, - GetLockmodeName(info->lockmode), - info->locktag.relId, - info->locktag.dbId, - nextpid); + appendStringInfo(&buf, + gettext("Proc %d waits for %s on relation %u of database %u; blocked by proc %d."), + info->pid, + GetLockmodeName(info->lockmode), + info->locktag.relId, + info->locktag.dbId, + nextpid); } } + ereport(ERROR, + (errcode(ERRCODE_T_R_DEADLOCK_DETECTED), + errmsg("deadlock detected"), + errdetail("%s", buf.data))); } /* diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index 0093138d41..2413f9a00f 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.56 2003/02/19 23:41:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.57 2003/07/24 22:04:13 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -82,7 +82,7 @@ InitLockTable(int maxBackends) LockTableId = lockmethod; if (!(LockTableId)) - elog(ERROR, "InitLockTable: couldn't initialize lock table"); + elog(ERROR, "could not initialize lock table"); #ifdef USER_LOCKS @@ -91,7 +91,7 @@ InitLockTable(int maxBackends) */ LongTermTableId = LockMethodTableRename(LockTableId); if (!(LongTermTableId)) - elog(ERROR, "InitLockTable: couldn't rename long-term lock table"); + elog(ERROR, "could not rename long-term lock table"); #endif return LockTableId; @@ -132,11 +132,11 @@ LockRelation(Relation relation, LOCKMODE lockmode) if (!LockAcquire(LockTableId, &tag, GetCurrentTransactionId(), lockmode, false)) - elog(ERROR, "LockRelation: LockAcquire failed"); + elog(ERROR, "LockAcquire failed"); /* * Check to see if the relcache entry has been invalidated while we - * were waiting to lock it. If so, rebuild it, or elog() trying. + * were waiting to lock it. If so, rebuild it, or ereport() trying. * Increment the refcount to ensure that RelationFlushRelation will * rebuild it and not just delete it. */ @@ -170,7 +170,7 @@ ConditionalLockRelation(Relation relation, LOCKMODE lockmode) /* * Check to see if the relcache entry has been invalidated while we - * were waiting to lock it. If so, rebuild it, or elog() trying. + * were waiting to lock it. If so, rebuild it, or ereport() trying. * Increment the refcount to ensure that RelationFlushRelation will * rebuild it and not just delete it. */ @@ -202,7 +202,7 @@ UnlockRelation(Relation relation, LOCKMODE lockmode) * * This routine grabs a session-level lock on the target relation. The * session lock persists across transaction boundaries. It will be removed - * when UnlockRelationForSession() is called, or if an elog(ERROR) occurs, + * when UnlockRelationForSession() is called, or if an ereport(ERROR) occurs, * or if the backend exits. * * Note that one should also grab a transaction-level lock on the rel @@ -221,7 +221,7 @@ LockRelationForSession(LockRelId *relid, LOCKMODE lockmode) if (!LockAcquire(LockTableId, &tag, InvalidTransactionId, lockmode, false)) - elog(ERROR, "LockRelationForSession: LockAcquire failed"); + elog(ERROR, "LockAcquire failed"); } /* @@ -259,7 +259,7 @@ LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode) if (!LockAcquire(LockTableId, &tag, GetCurrentTransactionId(), lockmode, false)) - elog(ERROR, "LockPage: LockAcquire failed"); + elog(ERROR, "LockAcquire failed"); } /* @@ -300,7 +300,7 @@ XactLockTableInsert(TransactionId xid) if (!LockAcquire(LockTableId, &tag, xid, ExclusiveLock, false)) - elog(ERROR, "XactLockTableInsert: LockAcquire failed"); + elog(ERROR, "LockAcquire failed"); } /* @@ -323,7 +323,7 @@ XactLockTableWait(TransactionId xid) if (!LockAcquire(LockTableId, &tag, myxid, ShareLock, false)) - elog(ERROR, "XactLockTableWait: LockAcquire failed"); + elog(ERROR, "LockAcquire failed"); LockRelease(LockTableId, &tag, myxid, ShareLock); diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 9fc0282632..e5ddc930b8 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.122 2003/02/19 23:41:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.123 2003/07/24 22:04:14 tgl Exp $ * * NOTES * Outside modules can create a lock table and acquire/release @@ -242,7 +242,7 @@ LockMethodTableInit(char *tabName, if (numModes >= MAX_LOCKMODES) { - elog(WARNING, "LockMethodTableInit: too many lock types %d greater than %d", + elog(WARNING, "too many lock types %d (limit is %d)", numModes, MAX_LOCKMODES); return INVALID_LOCKMETHOD; } @@ -261,7 +261,7 @@ LockMethodTableInit(char *tabName, ShmemInitStruct(shmemName, sizeof(LOCKMETHODTABLE), &found); if (!lockMethodTable) - elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); + elog(FATAL, "could not initialize lock table \"%s\"", tabName); /* * Lock the LWLock for the table (probably not necessary here) @@ -307,7 +307,7 @@ LockMethodTableInit(char *tabName, hash_flags); if (!lockMethodTable->lockHash) - elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); + elog(FATAL, "could not initialize lock table \"%s\"", tabName); Assert(lockMethodTable->lockHash->hash == tag_hash); /* @@ -327,7 +327,7 @@ LockMethodTableInit(char *tabName, hash_flags); if (!lockMethodTable->proclockHash) - elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); + elog(FATAL, "could not initialize lock table \"%s\"", tabName); /* init data structures */ LockMethodInit(lockMethodTable, conflictsP, numModes); @@ -377,7 +377,7 @@ LockMethodTableRename(LOCKMETHOD lockmethod) * Returns: TRUE if lock was acquired, FALSE otherwise. Note that * a FALSE return is to be expected if dontWait is TRUE; * but if dontWait is FALSE, only a parameter error can cause - * a FALSE return. (XXX probably we should just elog on parameter + * a FALSE return. (XXX probably we should just ereport on parameter * errors, instead of conflating this with failure to acquire lock?) * * Side Effects: The lock is acquired and recorded in lock tables. @@ -459,7 +459,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, lockMethodTable = LockMethodTable[lockmethod]; if (!lockMethodTable) { - elog(WARNING, "LockAcquire: bad lock table %d", lockmethod); + elog(WARNING, "bad lock table id: %d", lockmethod); return FALSE; } @@ -477,8 +477,9 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, if (!lock) { LWLockRelease(masterLock); - elog(ERROR, "LockAcquire: lock table %d is out of memory", - lockmethod); + ereport(ERROR, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); return FALSE; } @@ -524,7 +525,9 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, if (!proclock) { LWLockRelease(masterLock); - elog(ERROR, "LockAcquire: proclock table out of memory"); + ereport(ERROR, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); return FALSE; } @@ -569,7 +572,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, { if (i >= (int) lockmode) break; /* safe: we have a lock >= req level */ - elog(LOG, "Deadlock risk: raising lock level" + elog(LOG, "deadlock risk: raising lock level" " from %s to %s on object %u/%u/%u", lock_mode_names[i], lock_mode_names[lockmode], lock->tag.relId, lock->tag.dbId, lock->tag.objId.blkno); @@ -649,7 +652,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, (void *) proclock, HASH_REMOVE, NULL); if (!proclock) - elog(WARNING, "LockAcquire: remove proclock, table corrupted"); + elog(WARNING, "proclock table corrupted"); } else PROCLOCK_PRINT("LockAcquire: NHOLDING", proclock); @@ -906,13 +909,10 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, LOCK_PRINT("WaitOnLock: aborting on lock", lock, lockmode); LWLockRelease(lockMethodTable->masterLock); /* - * Now that we aren't holding the LockMgrLock, print details about - * the detected deadlock. We didn't want to do this before because - * sending elog messages to the client while holding the shared lock - * is bad for concurrency. + * Now that we aren't holding the LockMgrLock, we can give an error + * report including details about the detected deadlock. */ DeadLockReport(); - elog(ERROR, "deadlock detected"); /* not reached */ } @@ -1020,12 +1020,12 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, /* * let the caller print its own error message, too. Do not - * elog(ERROR). + * ereport(ERROR). */ if (!lock) { LWLockRelease(masterLock); - elog(WARNING, "LockRelease: no such lock"); + elog(WARNING, "no such lock"); return FALSE; } LOCK_PRINT("LockRelease: found", lock, lockmode); @@ -1048,10 +1048,10 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LWLockRelease(masterLock); #ifdef USER_LOCKS if (lockmethod == USER_LOCKMETHOD) - elog(WARNING, "LockRelease: no lock with this tag"); + elog(WARNING, "no lock with this tag"); else #endif - elog(WARNING, "LockRelease: proclock table corrupted"); + elog(WARNING, "proclock table corrupted"); return FALSE; } PROCLOCK_PRINT("LockRelease: found", proclock); @@ -1065,7 +1065,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, PROCLOCK_PRINT("LockRelease: WRONGTYPE", proclock); Assert(proclock->holding[lockmode] >= 0); LWLockRelease(masterLock); - elog(WARNING, "LockRelease: you don't own a lock of type %s", + elog(WARNING, "you don't own a lock of type %s", lock_mode_names[lockmode]); return FALSE; } @@ -1119,7 +1119,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, if (!lock) { LWLockRelease(masterLock); - elog(WARNING, "LockRelease: remove lock, table corrupted"); + elog(WARNING, "lock table corrupted"); return FALSE; } wakeupNeeded = false; /* should be false, but make sure */ @@ -1148,7 +1148,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, if (!proclock) { LWLockRelease(masterLock); - elog(WARNING, "LockRelease: remove proclock, table corrupted"); + elog(WARNING, "proclock table corrupted"); return FALSE; } } @@ -1197,7 +1197,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, lockMethodTable = LockMethodTable[lockmethod]; if (!lockMethodTable) { - elog(WARNING, "LockReleaseAll: bad lockmethod %d", lockmethod); + elog(WARNING, "bad lockmethod %d", lockmethod); return FALSE; } @@ -1301,7 +1301,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, if (!proclock) { LWLockRelease(masterLock); - elog(WARNING, "LockReleaseAll: proclock table corrupted"); + elog(WARNING, "proclock table corrupted"); return FALSE; } @@ -1319,7 +1319,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, if (!lock) { LWLockRelease(masterLock); - elog(WARNING, "LockReleaseAll: cannot remove lock from HTAB"); + elog(WARNING, "cannot remove lock from HTAB"); return FALSE; } } @@ -1334,7 +1334,7 @@ next_item: #ifdef LOCK_DEBUG if (lockmethod == USER_LOCKMETHOD ? Trace_userlocks : Trace_locks) - elog(LOG, "LockReleaseAll: done"); + elog(LOG, "LockReleaseAll done"); #endif return TRUE; diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 2d891b732d..78bf2f4d49 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.15 2003/06/11 22:37:45 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.16 2003/07/24 22:04:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -181,7 +181,7 @@ LWLockId LWLockAssign(void) { if (LWLockCounter[0] >= LWLockCounter[1]) - elog(FATAL, "No more LWLockIds available"); + elog(FATAL, "no more LWLockIds available"); return (LWLockId) (LWLockCounter[0]++); } @@ -278,7 +278,7 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode) * shared memory initialization. */ if (proc == NULL) - elog(FATAL, "LWLockAcquire: can't wait without a PGPROC structure"); + elog(FATAL, "cannot wait without a PGPROC structure"); proc->lwWaiting = true; proc->lwExclusive = (mode == LW_EXCLUSIVE); @@ -424,7 +424,7 @@ LWLockRelease(LWLockId lockid) break; } if (i < 0) - elog(ERROR, "LWLockRelease: lock %d is not held", (int) lockid); + elog(ERROR, "lock %d is not held", (int) lockid); num_held_lwlocks--; for (; i < num_held_lwlocks; i++) held_lwlocks[i] = held_lwlocks[i + 1]; @@ -503,10 +503,10 @@ LWLockRelease(LWLockId lockid) /* * LWLockReleaseAll - release all currently-held locks * - * Used to clean up after elog(ERROR). An important difference between this + * Used to clean up after ereport(ERROR). An important difference between this * function and retail LWLockRelease calls is that InterruptHoldoffCount is * unchanged by this operation. This is necessary since InterruptHoldoffCount - * has been set to an appropriate level earlier in error recovery. We could + * has been set to an appropriate level earlier in error recovery. We could * decrement it below zero if we allow it to drop for each released lock! */ void diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 02ab546902..eebd696c2c 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.130 2003/05/15 16:35:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.131 2003/07/24 22:04:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -148,7 +148,9 @@ InitProcGlobal(int maxBackends) proc = (PGPROC *) ShmemAlloc(sizeof(PGPROC)); if (!proc) - elog(FATAL, "cannot create new proc: out of memory"); + ereport(FATAL, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); MemSet(proc, 0, sizeof(PGPROC)); PGSemaphoreCreate(&proc->sem); proc->links.next = ProcGlobal->freeProcs; @@ -162,7 +164,9 @@ InitProcGlobal(int maxBackends) */ DummyProc = (PGPROC *) ShmemAlloc(sizeof(PGPROC)); if (!DummyProc) - elog(FATAL, "cannot create new proc: out of memory"); + ereport(FATAL, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); MemSet(DummyProc, 0, sizeof(PGPROC)); DummyProc->pid = 0; /* marks DummyProc as not in use */ PGSemaphoreCreate(&DummyProc->sem); @@ -189,10 +193,10 @@ InitProcess(void) * we are a backend, we inherit this by fork() from the postmaster). */ if (procglobal == NULL) - elog(PANIC, "InitProcess: Proc Header uninitialized"); + elog(PANIC, "proc header uninitialized"); if (MyProc != NULL) - elog(ERROR, "InitProcess: you already exist"); + elog(ERROR, "you already exist"); /* * Try to get a proc struct from the free list. If this fails, we @@ -216,7 +220,9 @@ InitProcess(void) * standard error message. */ SpinLockRelease(ProcStructLock); - elog(FATAL, "Sorry, too many clients already"); + ereport(FATAL, + (errcode(ERRCODE_TOO_MANY_CONNECTIONS), + errmsg("sorry, too many clients already"))); } /* @@ -270,17 +276,16 @@ InitDummyProcess(void) * inherit this by fork() from the postmaster). */ if (ProcGlobal == NULL || DummyProc == NULL) - elog(PANIC, "InitDummyProcess: Proc Header uninitialized"); + elog(PANIC, "proc header uninitialized"); if (MyProc != NULL) - elog(ERROR, "InitDummyProcess: you already exist"); + elog(ERROR, "you already exist"); /* * DummyProc should not presently be in use by anyone else */ if (DummyProc->pid != 0) - elog(FATAL, "InitDummyProcess: DummyProc is in use by PID %d", - DummyProc->pid); + elog(FATAL, "DummyProc is in use by PID %d", DummyProc->pid); MyProc = DummyProc; /* @@ -319,7 +324,7 @@ InitDummyProcess(void) * Returns true if we had been waiting for a lock, else false. * * (Normally, this would only happen if we accept a cancel/die - * interrupt while waiting; but an elog(ERROR) while waiting is + * interrupt while waiting; but an ereport(ERROR) while waiting is * within the realm of possibility, too.) */ bool @@ -655,7 +660,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, * running the rather expensive deadlock-check code in most cases. */ if (!enable_sig_alarm(DeadlockTimeout, false)) - elog(FATAL, "ProcSleep: Unable to set timer for process wakeup"); + elog(FATAL, "could not set timer for process wakeup"); /* * If someone wakes us between LWLockRelease and PGSemaphoreLock, @@ -677,7 +682,7 @@ ProcSleep(LOCKMETHODTABLE *lockMethodTable, * Disable the timer, if it's still running */ if (!disable_sig_alarm(false)) - elog(FATAL, "ProcSleep: Unable to disable timer for process wakeup"); + elog(FATAL, "could not disable timer for process wakeup"); /* * Now there is nothing for LockWaitCancel to do. |
