88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.90 2000/10/22 20:20:49 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.91 2000/10/23 04:10:06 vadim Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
5454#include "storage/smgr.h"
5555#include "utils/relcache.h"
5656
57+ #ifdef XLOG
58+ #include "catalog/pg_database.h"
59+ #endif
60+
5761extern SPINLOCK BufMgrLock ;
5862extern longint ReadBufferCount ;
5963extern longint ReadLocalBufferCount ;
@@ -611,7 +615,6 @@ BufferAlloc(Relation reln,
611615/* record the database name and relation name for this buffer */
612616strcpy (buf -> blind .dbname , (DatabaseName ) ?DatabaseName :"Recovery" );
613617strcpy (buf -> blind .relname ,RelationGetPhysicalRelationName (reln ));
614- buf -> relId = reln -> rd_lockInfo .lockRelId ;
615618
616619INIT_BUFFERTAG (& (buf -> tag ),reln ,blockNum );
617620if (!BufTableInsert (buf ))
711714FlushBuffer (Buffer buffer ,bool release )
712715{
713716BufferDesc * bufHdr ;
714- Oid bufdb ;
715717Relation bufrel ;
716718int status ;
717719
@@ -725,10 +727,7 @@ FlushBuffer(Buffer buffer, bool release)
725727
726728bufHdr = & BufferDescriptors [buffer - 1 ];
727729
728- bufdb = bufHdr -> relId .dbId ;
729-
730- Assert (bufdb == MyDatabaseId || bufdb == (Oid )NULL );
731- bufrel = RelationIdCacheGetRelation (bufHdr -> relId .relId );
730+ bufrel = RelationNodeCacheGetRelation (bufHdr -> tag .rnode );
732731
733732Assert (bufrel != (Relation )NULL );
734733
@@ -904,7 +903,7 @@ SetBufferDirtiedByMe(Buffer buffer, BufferDesc *bufHdr)
904903SpinRelease (BufMgrLock );
905904#endif /* OPTIMIZE_SINGLE */
906905
907- reln = RelationIdCacheGetRelation ( BufferRelidLastDirtied [ buffer - 1 ]. relId );
906+ reln = RelationNodeCacheGetRelation ( tagLastDirtied -> rnode );
908907
909908if (reln == (Relation )NULL )
910909{
@@ -938,7 +937,6 @@ SetBufferDirtiedByMe(Buffer buffer, BufferDesc *bufHdr)
938937}
939938
940939* tagLastDirtied = bufHdr -> tag ;
941- BufferRelidLastDirtied [buffer - 1 ]= bufHdr -> relId ;
942940BufferBlindLastDirtied [buffer - 1 ]= bufHdr -> blind ;
943941BufferDirtiedByMe [buffer - 1 ]= true;
944942}
@@ -1010,15 +1008,14 @@ BufferSync()
10101008if (RelFileNodeEquals (bufHdr -> tag .rnode ,BufferTagLastDirtied [i ].rnode )&&
10111009bufHdr -> tag .blockNum == BufferTagLastDirtied [i ].blockNum )
10121010{
1013- Oid bufrel = bufHdr -> relId .relId ;
1014-
10151011/*
10161012 * Try to find relation for buf. This could fail, if the
10171013 * rel has been flushed from the relcache since we dirtied
10181014 * the page. That should be uncommon, so paying the extra
10191015 * cost of a blind write when it happens seems OK.
10201016 */
1021- reln = RelationIdCacheGetRelation (bufrel );
1017+ if (!InRecovery )
1018+ reln = RelationNodeCacheGetRelation (bufHdr -> tag .rnode );
10221019
10231020/*
10241021 * We have to pin buffer to keep anyone from stealing it
@@ -1083,8 +1080,6 @@ BufferSync()
10831080}
10841081else
10851082{
1086- Assert (RelFileNodeEquals (reln -> rd_node ,
1087- BufferTagLastDirtied [i ].rnode ));
10881083status = smgrwrite (DEFAULT_SMGR ,reln ,
10891084bufHdr -> tag .blockNum ,
10901085(char * )MAKE_PTR (bufHdr -> data ));
@@ -1138,7 +1133,7 @@ BufferSync()
11381133SpinRelease (BufMgrLock );
11391134#endif /* OPTIMIZE_SINGLE */
11401135
1141- reln = RelationIdCacheGetRelation ( BufferRelidLastDirtied [i ].relId );
1136+ reln = RelationNodeCacheGetRelation ( BufferTagLastDirtied [i ].rnode );
11421137if (reln == (Relation )NULL )
11431138{
11441139status = smgrblindmarkdirty (DEFAULT_SMGR ,
@@ -1147,8 +1142,6 @@ BufferSync()
11471142}
11481143else
11491144{
1150- Assert (RelFileNodeEquals (reln -> rd_node ,
1151- BufferTagLastDirtied [i ].rnode ));
11521145status = smgrmarkdirty (DEFAULT_SMGR ,reln ,
11531146BufferTagLastDirtied [i ].blockNum );
11541147
@@ -1420,21 +1413,14 @@ static int
14201413BufferReplace (BufferDesc * bufHdr )
14211414{
14221415Relation reln ;
1423- Oid bufdb ,
1424- bufrel ;
14251416int status ;
14261417
14271418/*
14281419 * first try to find the reldesc in the cache, if no luck, don't
14291420 * bother to build the reldesc from scratch, just do a blind write.
14301421 */
1431- bufdb = bufHdr -> relId .dbId ;
1432- bufrel = bufHdr -> relId .relId ;
14331422
1434- if (bufdb == MyDatabaseId || bufdb == (Oid )NULL )
1435- reln = RelationIdCacheGetRelation (bufrel );
1436- else
1437- reln = (Relation )NULL ;
1423+ reln = RelationNodeCacheGetRelation (bufHdr -> tag .rnode );
14381424
14391425/* To check if block content changed while flushing. - vadim 01/17/97 */
14401426bufHdr -> flags &= ~BM_JUST_DIRTIED ;
@@ -1450,7 +1436,6 @@ BufferReplace(BufferDesc *bufHdr)
14501436
14511437if (reln != (Relation )NULL )
14521438{
1453- Assert (RelFileNodeEquals (bufHdr -> tag .rnode ,reln -> rd_node ));
14541439status = smgrwrite (DEFAULT_SMGR ,reln ,bufHdr -> tag .blockNum ,
14551440 (char * )MAKE_PTR (bufHdr -> data ));
14561441}
@@ -1519,7 +1504,6 @@ RelationGetNumberOfBlocks(Relation relation)
15191504void
15201505ReleaseRelationBuffers (Relation rel )
15211506{
1522- Oid relid = RelationGetRelid (rel );
15231507int i ;
15241508BufferDesc * bufHdr ;
15251509
@@ -1534,10 +1518,6 @@ ReleaseRelationBuffers(Relation rel)
15341518LocalRefCount [i ]= 0 ;
15351519bufHdr -> tag .rnode .relNode = InvalidOid ;
15361520}
1537- else
1538- {
1539- Assert (bufHdr -> relId .relId != relid );
1540- }
15411521}
15421522return ;
15431523}
@@ -1590,12 +1570,6 @@ ReleaseRelationBuffers(Relation rel)
15901570 */
15911571BufTableDelete (bufHdr );
15921572}
1593- else
1594- {
1595- Assert (bufHdr -> relId .relId != relid ||
1596- (bufHdr -> relId .dbId != MyDatabaseId &&
1597- bufHdr -> relId .dbId != InvalidOid ));
1598- }
15991573
16001574/*
16011575 * Also check to see if BufferDirtiedByMe info for this buffer
@@ -1608,7 +1582,7 @@ ReleaseRelationBuffers(Relation rel)
16081582 * this rel, since we hold exclusive lock on this rel.
16091583 */
16101584if (RelFileNodeEquals (rel -> rd_node ,
1611- BufferTagLastDirtied [i - 1 ].rnode ))
1585+ BufferTagLastDirtied [i - 1 ].rnode ))
16121586BufferDirtiedByMe [i - 1 ]= false;
16131587}
16141588
@@ -1673,11 +1647,6 @@ DropBuffers(Oid dbid)
16731647 */
16741648BufTableDelete (bufHdr );
16751649}
1676- else
1677- {
1678- Assert (bufHdr -> relId .dbId != dbid );
1679- }
1680-
16811650/*
16821651 * Also check to see if BufferDirtiedByMe info for this buffer
16831652 * refers to the target database, and clear it if so. This is
@@ -1824,7 +1793,6 @@ BufferPoolBlowaway()
18241793int
18251794FlushRelationBuffers (Relation rel ,BlockNumber firstDelBlock )
18261795{
1827- Oid relid = RelationGetRelid (rel );
18281796int i ;
18291797BufferDesc * bufHdr ;
18301798
@@ -1857,10 +1825,6 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
18571825bufHdr -> tag .rnode .relNode = InvalidOid ;
18581826}
18591827}
1860- else
1861- {
1862- Assert (bufHdr -> relId .relId != relid );
1863- }
18641828}
18651829return 0 ;
18661830}
@@ -1906,12 +1870,6 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
19061870BufTableDelete (bufHdr );
19071871}
19081872}
1909- else
1910- {
1911- Assert (bufHdr -> relId .relId != relid ||
1912- (bufHdr -> relId .dbId != MyDatabaseId &&
1913- bufHdr -> relId .dbId != InvalidOid ));
1914- }
19151873}
19161874SpinRelease (BufMgrLock );
19171875return 0 ;