8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -229,13 +229,17 @@ ReadBufferInternal(Relation reln, BlockNumber blockNum,
229
229
{
230
230
if (zero_damaged_pages )
231
231
{
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 ))));
234
236
MemSet ((char * )MAKE_PTR (bufHdr -> data ),0 ,BLCKSZ );
235
237
}
236
238
else
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 ))));
239
243
}
240
244
}
241
245
@@ -260,7 +264,7 @@ ReadBufferInternal(Relation reln, BlockNumber blockNum,
260
264
if (!BufTableDelete (bufHdr ))
261
265
{
262
266
LWLockRelease (BufMgrLock );
263
- elog (FATAL ,"BufRead: buffer table broken afterIO error" );
267
+ elog (FATAL ,"buffer table broken afterI/O error" );
264
268
}
265
269
/* remember that BufferAlloc() pinned the buffer */
266
270
UnpinBuffer (bufHdr );
@@ -430,9 +434,12 @@ BufferAlloc(Relation reln,
430
434
431
435
if (smok == FALSE)
432
436
{
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 )));
436
443
inProgress = FALSE;
437
444
buf -> flags |=BM_IO_ERROR ;
438
445
buf -> flags &= ~BM_IO_IN_PROGRESS ;
@@ -448,7 +455,7 @@ BufferAlloc(Relation reln,
448
455
*/
449
456
if (buf -> flags & BM_JUST_DIRTIED )
450
457
{
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" ,
452
459
buf -> tag .blockNum ,
453
460
buf -> tag .rnode .tblNode ,buf -> tag .rnode .relNode );
454
461
}
@@ -540,15 +547,15 @@ BufferAlloc(Relation reln,
540
547
if (!BufTableDelete (buf ))
541
548
{
542
549
LWLockRelease (BufMgrLock );
543
- elog (FATAL ,"buffer wasn't in the buffer table" );
550
+ elog (FATAL ,"buffer wasn't in the bufferhash table" );
544
551
}
545
552
546
553
INIT_BUFFERTAG (& (buf -> tag ),reln ,blockNum );
547
554
548
555
if (!BufTableInsert (buf ))
549
556
{
550
557
LWLockRelease (BufMgrLock );
551
- elog (FATAL ,"Buffer inlookup table twice" );
558
+ elog (FATAL ,"buffer inbuffer hash table twice" );
552
559
}
553
560
554
561
/*
@@ -587,7 +594,7 @@ write_buffer(Buffer buffer, bool release)
587
594
}
588
595
589
596
if (BAD_BUFFER_ID (buffer ))
590
- elog (ERROR ,"write_buffer: bad buffer %d" ,buffer );
597
+ elog (ERROR ,"bad buffer id: %d" ,buffer );
591
598
592
599
bufHdr = & BufferDescriptors [buffer - 1 ];
593
600
@@ -809,9 +816,12 @@ BufferSync(void)
809
816
}
810
817
811
818
if (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 )));
815
825
816
826
/*
817
827
* Note that it's safe to change cntxDirty here because of we
@@ -932,7 +942,7 @@ ResetBufferUsage(void)
932
942
*AtEOXact_Buffers - clean up at end of transaction.
933
943
*
934
944
*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
936
946
*buffer). During commit, we shouldn't need to do that, but check
937
947
*anyway to see if anyone leaked a buffer reference count.
938
948
*/
@@ -949,8 +959,8 @@ AtEOXact_Buffers(bool isCommit)
949
959
950
960
if (isCommit )
951
961
elog (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)" ,
954
964
i ,buf -> freeNext ,buf -> freePrev ,
955
965
buf -> tag .rnode .tblNode ,buf -> tag .rnode .relNode ,
956
966
buf -> tag .blockNum ,buf -> flags ,
@@ -1206,8 +1216,10 @@ DropRelFileNodeBuffers(RelFileNode rnode, bool istemp)
1206
1216
{
1207
1217
/* the sole pin should be ours */
1208
1218
if (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)" ,
1210
1220
bufHdr -> tag .blockNum ,
1221
+ bufHdr -> tag .rnode .tblNode ,
1222
+ bufHdr -> tag .rnode .relNode ,
1211
1223
PrivateRefCount [i - 1 ],bufHdr -> refcount );
1212
1224
/* Make sure it will be released */
1213
1225
PrivateRefCount [i - 1 ]= 1 ;
@@ -1427,7 +1439,7 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
1427
1439
if (status == SM_FAIL )
1428
1440
{
1429
1441
error_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" ,
1431
1443
RelationGetRelationName (rel ),firstDelBlock ,
1432
1444
bufHdr -> tag .blockNum );
1433
1445
return (-1 );
@@ -1438,7 +1450,7 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
1438
1450
if (LocalRefCount [i ]> 0 )
1439
1451
{
1440
1452
error_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)" ,
1442
1454
RelationGetRelationName (rel ),firstDelBlock ,
1443
1455
bufHdr -> tag .blockNum ,LocalRefCount [i ]);
1444
1456
return (-2 );
@@ -1495,10 +1507,12 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
1495
1507
(char * )MAKE_PTR (bufHdr -> data ));
1496
1508
1497
1509
if (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 )));
1502
1516
1503
1517
BufferFlushCount ++ ;
1504
1518
@@ -1522,7 +1536,7 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
1522
1536
{
1523
1537
LWLockRelease (BufMgrLock );
1524
1538
error_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)" ,
1526
1540
RelationGetRelationName (rel ),firstDelBlock ,
1527
1541
bufHdr -> tag .blockNum ,
1528
1542
PrivateRefCount [i ],bufHdr -> refcount );
@@ -1825,7 +1839,7 @@ SetBufferCommitInfoNeedsSave(Buffer buffer)
1825
1839
}
1826
1840
1827
1841
if (BAD_BUFFER_ID (buffer ))
1828
- elog (ERROR ,"SetBufferCommitInfoNeedsSave: bad buffer %d" ,buffer );
1842
+ elog (ERROR ,"bad buffer id: %d" ,buffer );
1829
1843
1830
1844
bufHdr = & BufferDescriptors [buffer - 1 ];
1831
1845
@@ -1919,7 +1933,7 @@ LockBuffer(Buffer buffer, int mode)
1919
1933
buf -> cntxDirty = true;
1920
1934
}
1921
1935
else
1922
- elog (ERROR ,"LockBuffer: unknown lock mode %d" ,mode );
1936
+ elog (ERROR ,"unrecognized buffer lock mode: %d" ,mode );
1923
1937
}
1924
1938
1925
1939
/*
@@ -1950,14 +1964,16 @@ LockBufferForCleanup(Buffer buffer)
1950
1964
{
1951
1965
/* There should be exactly one pin */
1952
1966
if (LocalRefCount [- buffer - 1 ]!= 1 )
1953
- elog (ERROR ,"LockBufferForCleanup: wrong local pin count" );
1967
+ elog (ERROR ,"incorrect local pin count: %ld" ,
1968
+ LocalRefCount [- buffer - 1 ]);
1954
1969
/* Nobody else to wait for */
1955
1970
return ;
1956
1971
}
1957
1972
1958
1973
/* There should be exactly one local pin */
1959
1974
if (PrivateRefCount [buffer - 1 ]!= 1 )
1960
- elog (ERROR ,"LockBufferForCleanup: wrong local pin count" );
1975
+ elog (ERROR ,"incorrect local pin count: %ld" ,
1976
+ PrivateRefCount [buffer - 1 ]);
1961
1977
1962
1978
bufHdr = & BufferDescriptors [buffer - 1 ];
1963
1979
buflock = & (BufferLocks [buffer - 1 ]);
@@ -1979,7 +1995,7 @@ LockBufferForCleanup(Buffer buffer)
1979
1995
{
1980
1996
LWLockRelease (BufMgrLock );
1981
1997
LockBuffer (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" );
1983
1999
}
1984
2000
bufHdr -> wait_backend_id = MyBackendId ;
1985
2001
bufHdr -> flags |=BM_PIN_COUNT_WAITER ;
@@ -2102,9 +2118,13 @@ AbortBufferIO(void)
2102
2118
/* Issue notice if this is not the first failure... */
2103
2119
if (buf -> flags & BM_IO_ERROR )
2104
2120
{
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." )));
2108
2128
}
2109
2129
buf -> flags |=BM_DIRTY ;
2110
2130
}