Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8864603

Browse files
committed
Minor code cleanup in bufmgr.c and bufmgr.h, mainly by moving repeated
lines of code into internal routines (drop_relfilenode_buffers,release_buffer) and by hiding unused routines (PrintBufferDescs,PrintPinnedBufs) behind #ifdef NOT_USED. Remove AbortBufferIO()declaration from bufmgr.c (already declared in bufmgr.h)Manfred Koizar
1 parent97bfffe commit8864603

File tree

2 files changed

+70
-119
lines changed

2 files changed

+70
-119
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 67 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.126 2002/06/20 20:29:34 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.127 2002/07/02 05:47:37 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -71,7 +71,6 @@ static void WaitIO(BufferDesc *buf);
7171
staticvoidStartBufferIO(BufferDesc*buf,boolforInput);
7272
staticvoidTerminateBufferIO(BufferDesc*buf);
7373
staticvoidContinueBufferIO(BufferDesc*buf,boolforInput);
74-
externvoidAbortBufferIO(void);
7574

7675
/*
7776
* Macro : BUFFER_IS_BROKEN
@@ -85,9 +84,14 @@ static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
8584
bool*foundPtr);
8685
staticintReleaseBufferWithBufferLock(Bufferbuffer);
8786
staticintBufferReplace(BufferDesc*bufHdr);
87+
#ifdefNOT_USED
8888
voidPrintBufferDescs(void);
89+
#endif
8990

9091
staticvoidwrite_buffer(Bufferbuffer,boolunpin);
92+
staticvoiddrop_relfilenode_buffers(RelFileNodernode,
93+
booldo_local,booldo_both);
94+
staticintrelease_buffer(Bufferbuffer,boolhavelock);
9195

9296
/*
9397
* ReadBuffer -- returns a buffer containing the requested
@@ -1097,42 +1101,35 @@ RelationGetNumberOfBlocks(Relation relation)
10971101
returnrelation->rd_nblocks;
10981102
}
10991103

1100-
/* ---------------------------------------------------------------------
1101-
*DropRelationBuffers
1102-
*
1103-
*This function removes all the buffered pages for a relation
1104-
*from the buffer pool. Dirty pages are simply dropped, without
1105-
*bothering to write them out first.This is NOT rollback-able,
1106-
*and so should be used only with extreme caution!
1107-
*
1108-
*We assume that the caller holds an exclusive lock on the relation,
1109-
*which should assure that no new buffers will be acquired for the rel
1110-
*meanwhile.
1104+
/*
1105+
* drop_relfilenode_buffers -- common functionality for
1106+
* DropRelationBuffers and
1107+
* DropRelFileNodeBuffers
11111108
*
11121109
*XXX currently it sequentially searches the buffer pool, should be
11131110
*changed to more clever ways of searching.
1114-
* --------------------------------------------------------------------
11151111
*/
1116-
void
1117-
DropRelationBuffers(Relationrel)
1112+
staticvoid
1113+
drop_relfilenode_buffers(RelFileNodernode,booldo_local,booldo_both)
11181114
{
11191115
inti;
11201116
BufferDesc*bufHdr;
11211117

1122-
if (rel->rd_myxactonly)
1118+
if (do_local)
11231119
{
11241120
for (i=0;i<NLocBuffer;i++)
11251121
{
11261122
bufHdr=&LocalBufferDescriptors[i];
1127-
if (RelFileNodeEquals(bufHdr->tag.rnode,rel->rd_node))
1123+
if (RelFileNodeEquals(bufHdr->tag.rnode,rnode))
11281124
{
11291125
bufHdr->flags &= ~(BM_DIRTY |BM_JUST_DIRTIED);
11301126
bufHdr->cntxDirty= false;
11311127
LocalRefCount[i]=0;
11321128
bufHdr->tag.rnode.relNode=InvalidOid;
11331129
}
11341130
}
1135-
return;
1131+
if (!do_both)
1132+
return;
11361133
}
11371134

11381135
LWLockAcquire(BufMgrLock,LW_EXCLUSIVE);
@@ -1141,7 +1138,7 @@ DropRelationBuffers(Relation rel)
11411138
{
11421139
bufHdr=&BufferDescriptors[i-1];
11431140
recheck:
1144-
if (RelFileNodeEquals(bufHdr->tag.rnode,rel->rd_node))
1141+
if (RelFileNodeEquals(bufHdr->tag.rnode,rnode))
11451142
{
11461143
/*
11471144
* If there is I/O in progress, better wait till it's done;
@@ -1187,6 +1184,25 @@ DropRelationBuffers(Relation rel)
11871184
LWLockRelease(BufMgrLock);
11881185
}
11891186

1187+
/* ---------------------------------------------------------------------
1188+
*DropRelationBuffers
1189+
*
1190+
*This function removes all the buffered pages for a relation
1191+
*from the buffer pool. Dirty pages are simply dropped, without
1192+
*bothering to write them out first.This is NOT rollback-able,
1193+
*and so should be used only with extreme caution!
1194+
*
1195+
*We assume that the caller holds an exclusive lock on the relation,
1196+
*which should assure that no new buffers will be acquired for the rel
1197+
*meanwhile.
1198+
* --------------------------------------------------------------------
1199+
*/
1200+
void
1201+
DropRelationBuffers(Relationrel)
1202+
{
1203+
drop_relfilenode_buffers(rel->rd_node,rel->rd_myxactonly, false);
1204+
}
1205+
11901206
/* ---------------------------------------------------------------------
11911207
*DropRelFileNodeBuffers
11921208
*
@@ -1201,73 +1217,8 @@ DropRelationBuffers(Relation rel)
12011217
void
12021218
DropRelFileNodeBuffers(RelFileNodernode)
12031219
{
1204-
inti;
1205-
BufferDesc*bufHdr;
1206-
12071220
/* We have to search both local and shared buffers... */
1208-
1209-
for (i=0;i<NLocBuffer;i++)
1210-
{
1211-
bufHdr=&LocalBufferDescriptors[i];
1212-
if (RelFileNodeEquals(bufHdr->tag.rnode,rnode))
1213-
{
1214-
bufHdr->flags &= ~(BM_DIRTY |BM_JUST_DIRTIED);
1215-
bufHdr->cntxDirty= false;
1216-
LocalRefCount[i]=0;
1217-
bufHdr->tag.rnode.relNode=InvalidOid;
1218-
}
1219-
}
1220-
1221-
LWLockAcquire(BufMgrLock,LW_EXCLUSIVE);
1222-
1223-
for (i=1;i <=NBuffers;i++)
1224-
{
1225-
bufHdr=&BufferDescriptors[i-1];
1226-
recheck:
1227-
if (RelFileNodeEquals(bufHdr->tag.rnode,rnode))
1228-
{
1229-
/*
1230-
* If there is I/O in progress, better wait till it's done;
1231-
* don't want to delete the relation out from under someone
1232-
* who's just trying to flush the buffer!
1233-
*/
1234-
if (bufHdr->flags&BM_IO_IN_PROGRESS)
1235-
{
1236-
WaitIO(bufHdr);
1237-
1238-
/*
1239-
* By now, the buffer very possibly belongs to some other
1240-
* rel, so check again before proceeding.
1241-
*/
1242-
gotorecheck;
1243-
}
1244-
/* Now we can do what we came for */
1245-
bufHdr->flags &= ~(BM_DIRTY |BM_JUST_DIRTIED);
1246-
bufHdr->cntxDirty= false;
1247-
1248-
/*
1249-
* Release any refcount we may have.
1250-
*
1251-
* This is very probably dead code, and if it isn't then it's
1252-
* probably wrong.I added the Assert to find out --- tgl
1253-
* 11/99.
1254-
*/
1255-
if (!(bufHdr->flags&BM_FREE))
1256-
{
1257-
/* Assert checks that buffer will actually get freed! */
1258-
Assert(PrivateRefCount[i-1]==1&&
1259-
bufHdr->refcount==1);
1260-
ReleaseBufferWithBufferLock(i);
1261-
}
1262-
1263-
/*
1264-
* And mark the buffer as no longer occupied by this rel.
1265-
*/
1266-
BufTableDelete(bufHdr);
1267-
}
1268-
}
1269-
1270-
LWLockRelease(BufMgrLock);
1221+
drop_relfilenode_buffers(rnode, true, true);
12711222
}
12721223

12731224
/* ---------------------------------------------------------------------
@@ -1343,6 +1294,7 @@ DropBuffers(Oid dbid)
13431294
*use only.
13441295
* -----------------------------------------------------------------
13451296
*/
1297+
#ifdefNOT_USED
13461298
void
13471299
PrintBufferDescs()
13481300
{
@@ -1375,7 +1327,9 @@ blockNum=%u, flags=0x%x, refcount=%d %ld)",
13751327
}
13761328
}
13771329
}
1330+
#endif
13781331

1332+
#ifdefNOT_USED
13791333
void
13801334
PrintPinnedBufs()
13811335
{
@@ -1395,6 +1349,7 @@ blockNum=%u, flags=0x%x, refcount=%d %ld)",
13951349
}
13961350
LWLockRelease(BufMgrLock);
13971351
}
1352+
#endif
13981353

13991354
/*
14001355
* BufferPoolBlowaway
@@ -1589,14 +1544,12 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
15891544
return0;
15901545
}
15911546

1592-
#undef ReleaseBuffer
1593-
15941547
/*
1595-
*ReleaseBuffer --remove the pin on a buffer without
1596-
*marking it dirty.
1548+
*release_buffer --common functionality for
1549+
* ReleaseBuffer and ReleaseBufferWithBufferLock
15971550
*/
1598-
int
1599-
ReleaseBuffer(Bufferbuffer)
1551+
staticint
1552+
release_buffer(Bufferbuffer,boolhavelock)
16001553
{
16011554
BufferDesc*bufHdr;
16021555

@@ -1617,42 +1570,38 @@ ReleaseBuffer(Buffer buffer)
16171570
PrivateRefCount[buffer-1]--;
16181571
else
16191572
{
1620-
LWLockAcquire(BufMgrLock,LW_EXCLUSIVE);
1573+
if (!havelock)
1574+
LWLockAcquire(BufMgrLock,LW_EXCLUSIVE);
1575+
16211576
UnpinBuffer(bufHdr);
1622-
LWLockRelease(BufMgrLock);
1577+
1578+
if (!havelock)
1579+
LWLockRelease(BufMgrLock);
16231580
}
16241581

16251582
returnSTATUS_OK;
16261583
}
16271584

1585+
#undef ReleaseBuffer
1586+
1587+
/*
1588+
* ReleaseBuffer -- remove the pin on a buffer without
1589+
*marking it dirty.
1590+
*/
1591+
int
1592+
ReleaseBuffer(Bufferbuffer)
1593+
{
1594+
returnrelease_buffer(buffer, false);
1595+
}
1596+
16281597
/*
16291598
* ReleaseBufferWithBufferLock
16301599
*Same as ReleaseBuffer except we hold the bufmgr lock
16311600
*/
16321601
staticint
16331602
ReleaseBufferWithBufferLock(Bufferbuffer)
16341603
{
1635-
BufferDesc*bufHdr;
1636-
1637-
if (BufferIsLocal(buffer))
1638-
{
1639-
Assert(LocalRefCount[-buffer-1]>0);
1640-
LocalRefCount[-buffer-1]--;
1641-
returnSTATUS_OK;
1642-
}
1643-
1644-
if (BAD_BUFFER_ID(buffer))
1645-
returnSTATUS_ERROR;
1646-
1647-
bufHdr=&BufferDescriptors[buffer-1];
1648-
1649-
Assert(PrivateRefCount[buffer-1]>0);
1650-
if (PrivateRefCount[buffer-1]>1)
1651-
PrivateRefCount[buffer-1]--;
1652-
else
1653-
UnpinBuffer(bufHdr);
1654-
1655-
returnSTATUS_OK;
1604+
returnrelease_buffer(buffer, true);
16561605
}
16571606

16581607

@@ -1695,7 +1644,7 @@ refcount = %ld, file: %s, line: %d\n",
16951644
#endif
16961645

16971646
#ifdefNOT_USED
1698-
int
1647+
Buffer
16991648
ReleaseAndReadBuffer_Debug(char*file,
17001649
intline,
17011650
Bufferbuffer,
@@ -2117,7 +2066,7 @@ TerminateBufferIO(BufferDesc *buf)
21172066
{
21182067
Assert(buf==InProgressBuf);
21192068
LWLockRelease(buf->io_in_progress_lock);
2120-
InProgressBuf= (BufferDesc*)0;
2069+
InProgressBuf= (BufferDesc*)NULL;
21212070
}
21222071

21232072
/*
@@ -2142,7 +2091,7 @@ ContinueBufferIO(BufferDesc *buf, bool forInput)
21422091
void
21432092
InitBufferIO(void)
21442093
{
2145-
InProgressBuf= (BufferDesc*)0;
2094+
InProgressBuf= (BufferDesc*)NULL;
21462095
}
21472096
#endif
21482097

‎src/include/storage/bufmgr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: bufmgr.h,v 1.60 2002/06/20 20:29:52 momjian Exp $
10+
* $Id: bufmgr.h,v 1.61 2002/07/02 05:47:37 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -167,7 +167,9 @@ extern intFlushRelationBuffers(Relation rel, BlockNumber firstDelBlock);
167167
externvoidDropRelationBuffers(Relationrel);
168168
externvoidDropRelFileNodeBuffers(RelFileNodernode);
169169
externvoidDropBuffers(Oiddbid);
170+
#ifdefNOT_USED
170171
externvoidPrintPinnedBufs(void);
172+
#endif
171173
externintBufferShmemSize(void);
172174
externRelFileNodeBufferGetFileNode(Bufferbuffer);
173175

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp