88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.136 2003/05/10 19 :04:30 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.137 2003/07/24 22 :04:08 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -229,13 +229,17 @@ ReadBufferInternal(Relation reln, BlockNumber blockNum,
229229{
230230if (zero_damaged_pages )
231231{
232- elog (WARNING ,"Invalid page header in block %u of %s; zeroing out page" ,
233- blockNum ,RelationGetRelationName (reln ));
232+ ereport (WARNING ,
233+ (errcode (ERRCODE_DATA_CORRUPTED ),
234+ errmsg ("invalid page header in block %u of \"%s\"; zeroing out page" ,
235+ blockNum ,RelationGetRelationName (reln ))));
234236MemSet ((char * )MAKE_PTR (bufHdr -> data ),0 ,BLCKSZ );
235237}
236238else
237- elog (ERROR ,"Invalid page header in block %u of %s" ,
238- blockNum ,RelationGetRelationName (reln ));
239+ ereport (ERROR ,
240+ (errcode (ERRCODE_DATA_CORRUPTED ),
241+ errmsg ("invalid page header in block %u of \"%s\"" ,
242+ blockNum ,RelationGetRelationName (reln ))));
239243}
240244}
241245
@@ -260,7 +264,7 @@ ReadBufferInternal(Relation reln, BlockNumber blockNum,
260264if (!BufTableDelete (bufHdr ))
261265{
262266LWLockRelease (BufMgrLock );
263- elog (FATAL ,"BufRead: buffer table broken afterIO error" );
267+ elog (FATAL ,"buffer table broken afterI/O error" );
264268}
265269/* remember that BufferAlloc() pinned the buffer */
266270UnpinBuffer (bufHdr );
@@ -430,9 +434,12 @@ BufferAlloc(Relation reln,
430434
431435if (smok == FALSE)
432436{
433- elog (WARNING ,"BufferAlloc: cannot write block %u for %u/%u" ,
434- buf -> tag .blockNum ,
435- buf -> tag .rnode .tblNode ,buf -> tag .rnode .relNode );
437+ ereport (WARNING ,
438+ (errcode (ERRCODE_IO_ERROR ),
439+ errmsg ("could not write block %u of %u/%u" ,
440+ buf -> tag .blockNum ,
441+ buf -> tag .rnode .tblNode ,
442+ buf -> tag .rnode .relNode )));
436443inProgress = FALSE;
437444buf -> flags |=BM_IO_ERROR ;
438445buf -> flags &= ~BM_IO_IN_PROGRESS ;
@@ -448,7 +455,7 @@ BufferAlloc(Relation reln,
448455 */
449456if (buf -> flags & BM_JUST_DIRTIED )
450457{
451- elog (PANIC ,"BufferAlloc: content of block %u( %u/%u) changed while flushing" ,
458+ elog (PANIC ,"content of block %uof %u/%u changed while flushing" ,
452459buf -> tag .blockNum ,
453460buf -> tag .rnode .tblNode ,buf -> tag .rnode .relNode );
454461}
@@ -540,15 +547,15 @@ BufferAlloc(Relation reln,
540547if (!BufTableDelete (buf ))
541548{
542549LWLockRelease (BufMgrLock );
543- elog (FATAL ,"buffer wasn't in the buffer table" );
550+ elog (FATAL ,"buffer wasn't in the bufferhash table" );
544551}
545552
546553INIT_BUFFERTAG (& (buf -> tag ),reln ,blockNum );
547554
548555if (!BufTableInsert (buf ))
549556{
550557LWLockRelease (BufMgrLock );
551- elog (FATAL ,"Buffer inlookup table twice" );
558+ elog (FATAL ,"buffer inbuffer hash table twice" );
552559}
553560
554561/*
@@ -587,7 +594,7 @@ write_buffer(Buffer buffer, bool release)
587594}
588595
589596if (BAD_BUFFER_ID (buffer ))
590- elog (ERROR ,"write_buffer: bad buffer %d" ,buffer );
597+ elog (ERROR ,"bad buffer id: %d" ,buffer );
591598
592599bufHdr = & BufferDescriptors [buffer - 1 ];
593600
@@ -809,9 +816,12 @@ BufferSync(void)
809816}
810817
811818if (status == SM_FAIL )/* disk failure ?! */
812- elog (PANIC ,"BufferSync: cannot write %u for %u/%u" ,
813- bufHdr -> tag .blockNum ,
814- bufHdr -> tag .rnode .tblNode ,bufHdr -> tag .rnode .relNode );
819+ ereport (PANIC ,
820+ (errcode (ERRCODE_IO_ERROR ),
821+ errmsg ("could not write block %u of %u/%u" ,
822+ bufHdr -> tag .blockNum ,
823+ bufHdr -> tag .rnode .tblNode ,
824+ bufHdr -> tag .rnode .relNode )));
815825
816826/*
817827 * Note that it's safe to change cntxDirty here because of we
@@ -932,7 +942,7 @@ ResetBufferUsage(void)
932942 *AtEOXact_Buffers - clean up at end of transaction.
933943 *
934944 *During abort, we need to release any buffer pins we're holding
935- *(this cleans up in caseelog interrupted a routine that pins a
945+ *(this cleans up in caseereport interrupted a routine that pins a
936946 *buffer). During commit, we shouldn't need to do that, but check
937947 *anyway to see if anyone leaked a buffer reference count.
938948 */
@@ -949,8 +959,8 @@ AtEOXact_Buffers(bool isCommit)
949959
950960if (isCommit )
951961elog (WARNING ,
952- "Buffer Leak : [%03d] (freeNext=%d, freePrev=%d, "
953- "rel=%u/%u, blockNum=%u, flags=0x%x, refcount=%d %ld)" ,
962+ "buffer refcount leak : [%03d] (freeNext=%d, freePrev=%d, "
963+ "rel=%u/%u, blockNum=%u, flags=0x%x, refcount=%d %ld)" ,
954964i ,buf -> freeNext ,buf -> freePrev ,
955965buf -> tag .rnode .tblNode ,buf -> tag .rnode .relNode ,
956966buf -> tag .blockNum ,buf -> flags ,
@@ -1206,8 +1216,10 @@ DropRelFileNodeBuffers(RelFileNode rnode, bool istemp)
12061216{
12071217/* the sole pin should be ours */
12081218if (bufHdr -> refcount != 1 || PrivateRefCount [i - 1 ]== 0 )
1209- elog (FATAL ,"DropRelFileNodeBuffers: block %uis referenced (private %ld, global %d)" ,
1219+ elog (FATAL ,"block %uof %u/%u is still referenced (private %ld, global %d)" ,
12101220bufHdr -> tag .blockNum ,
1221+ bufHdr -> tag .rnode .tblNode ,
1222+ bufHdr -> tag .rnode .relNode ,
12111223PrivateRefCount [i - 1 ],bufHdr -> refcount );
12121224/* Make sure it will be released */
12131225PrivateRefCount [i - 1 ]= 1 ;
@@ -1427,7 +1439,7 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
14271439if (status == SM_FAIL )
14281440{
14291441error_context_stack = errcontext .previous ;
1430- elog (WARNING ,"FlushRelationBuffers(%s (local), %u): block %u is dirty, could not flush it" ,
1442+ elog (WARNING ,"FlushRelationBuffers(\"%s\" (local), %u): block %u is dirty, could not flush it" ,
14311443RelationGetRelationName (rel ),firstDelBlock ,
14321444bufHdr -> tag .blockNum );
14331445return (-1 );
@@ -1438,7 +1450,7 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
14381450if (LocalRefCount [i ]> 0 )
14391451{
14401452error_context_stack = errcontext .previous ;
1441- elog (WARNING ,"FlushRelationBuffers(%s (local), %u): block %u is referenced (%ld)" ,
1453+ elog (WARNING ,"FlushRelationBuffers(\"%s\" (local), %u): block %u is referenced (%ld)" ,
14421454RelationGetRelationName (rel ),firstDelBlock ,
14431455bufHdr -> tag .blockNum ,LocalRefCount [i ]);
14441456return (-2 );
@@ -1495,10 +1507,12 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
14951507 (char * )MAKE_PTR (bufHdr -> data ));
14961508
14971509if (status == SM_FAIL )/* disk failure ?! */
1498- elog (PANIC ,"FlushRelationBuffers: cannot write %u for %u/%u" ,
1499- bufHdr -> tag .blockNum ,
1500- bufHdr -> tag .rnode .tblNode ,
1501- bufHdr -> tag .rnode .relNode );
1510+ ereport (PANIC ,
1511+ (errcode (ERRCODE_IO_ERROR ),
1512+ errmsg ("could not write block %u of %u/%u" ,
1513+ bufHdr -> tag .blockNum ,
1514+ bufHdr -> tag .rnode .tblNode ,
1515+ bufHdr -> tag .rnode .relNode )));
15021516
15031517BufferFlushCount ++ ;
15041518
@@ -1522,7 +1536,7 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
15221536{
15231537LWLockRelease (BufMgrLock );
15241538error_context_stack = errcontext .previous ;
1525- elog (WARNING ,"FlushRelationBuffers(%s , %u): block %u is referenced (private %ld, global %d)" ,
1539+ elog (WARNING ,"FlushRelationBuffers(\"%s\" , %u): block %u is referenced (private %ld, global %d)" ,
15261540RelationGetRelationName (rel ),firstDelBlock ,
15271541bufHdr -> tag .blockNum ,
15281542PrivateRefCount [i ],bufHdr -> refcount );
@@ -1825,7 +1839,7 @@ SetBufferCommitInfoNeedsSave(Buffer buffer)
18251839}
18261840
18271841if (BAD_BUFFER_ID (buffer ))
1828- elog (ERROR ,"SetBufferCommitInfoNeedsSave: bad buffer %d" ,buffer );
1842+ elog (ERROR ,"bad buffer id: %d" ,buffer );
18291843
18301844bufHdr = & BufferDescriptors [buffer - 1 ];
18311845
@@ -1919,7 +1933,7 @@ LockBuffer(Buffer buffer, int mode)
19191933buf -> cntxDirty = true;
19201934}
19211935else
1922- elog (ERROR ,"LockBuffer: unknown lock mode %d" ,mode );
1936+ elog (ERROR ,"unrecognized buffer lock mode: %d" ,mode );
19231937}
19241938
19251939/*
@@ -1950,14 +1964,16 @@ LockBufferForCleanup(Buffer buffer)
19501964{
19511965/* There should be exactly one pin */
19521966if (LocalRefCount [- buffer - 1 ]!= 1 )
1953- elog (ERROR ,"LockBufferForCleanup: wrong local pin count" );
1967+ elog (ERROR ,"incorrect local pin count: %ld" ,
1968+ LocalRefCount [- buffer - 1 ]);
19541969/* Nobody else to wait for */
19551970return ;
19561971}
19571972
19581973/* There should be exactly one local pin */
19591974if (PrivateRefCount [buffer - 1 ]!= 1 )
1960- elog (ERROR ,"LockBufferForCleanup: wrong local pin count" );
1975+ elog (ERROR ,"incorrect local pin count: %ld" ,
1976+ PrivateRefCount [buffer - 1 ]);
19611977
19621978bufHdr = & BufferDescriptors [buffer - 1 ];
19631979buflock = & (BufferLocks [buffer - 1 ]);
@@ -1979,7 +1995,7 @@ LockBufferForCleanup(Buffer buffer)
19791995{
19801996LWLockRelease (BufMgrLock );
19811997LockBuffer (buffer ,BUFFER_LOCK_UNLOCK );
1982- elog (ERROR ,"Multiple backends attempting to wait for pincount 1" );
1998+ elog (ERROR ,"multiple backends attempting to wait for pincount 1" );
19831999}
19842000bufHdr -> wait_backend_id = MyBackendId ;
19852001bufHdr -> flags |=BM_PIN_COUNT_WAITER ;
@@ -2102,9 +2118,13 @@ AbortBufferIO(void)
21022118/* Issue notice if this is not the first failure... */
21032119if (buf -> flags & BM_IO_ERROR )
21042120{
2105- elog (WARNING ,"write error may be permanent: cannot write block %u for %u/%u" ,
2106- buf -> tag .blockNum ,
2107- buf -> tag .rnode .tblNode ,buf -> tag .rnode .relNode );
2121+ ereport (WARNING ,
2122+ (errcode (ERRCODE_IO_ERROR ),
2123+ errmsg ("could not write block %u of %u/%u" ,
2124+ buf -> tag .blockNum ,
2125+ buf -> tag .rnode .tblNode ,
2126+ buf -> tag .rnode .relNode ),
2127+ errdetail ("Multiple failures --- write error may be permanent." )));
21082128}
21092129buf -> flags |=BM_DIRTY ;
21102130}