Skip to content

Commit 5fb82eb

Browse files
committed
Blowaway relation buffers from buffer pool before truncation:
+ BlowawayRelationBuffers(relation, blocknumber)
1 parent 708f67c commit 5fb82eb

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.25 1997/09/18 20:21:21 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.26 1997/09/22 07:13:56 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -99,6 +99,9 @@ static int FlushBuffer(Buffer buffer, bool release);
9999
static void BufferSync(void);
100100
static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld);
101101

102+
/* not static but used by vacuum only ... */
103+
int BlowawayRelationBuffers(Relation rdesc, BlockNumber block);
104+
102105
/* ---------------------------------------------------
103106
* RelationGetBufferWithBuffer
104107
* see if the given buffer is what we want
@@ -1603,6 +1606,67 @@ BufferPoolBlowaway()
16031606

16041607
#endif
16051608

1609+
/* ---------------------------------------------------------------------
1610+
* BlowawayRelationBuffers
1611+
*
1612+
* This function blowaway all the pages with blocknumber >= passed
1613+
* of a relation in the buffer pool. Used by vacuum before truncation...
1614+
*
1615+
* Returns: 0 - Ok, -1 - DIRTY, -2 - PINNED
1616+
*
1617+
* XXX currently it sequentially searches the buffer pool, should be
1618+
* changed to more clever ways of searching.
1619+
* --------------------------------------------------------------------
1620+
*/
1621+
int
1622+
BlowawayRelationBuffers(Relation rdesc, BlockNumber block)
1623+
{
1624+
register int i;
1625+
BufferDesc *buf;
1626+
1627+
if (rdesc->rd_islocal)
1628+
{
1629+
for (i = 0; i < NLocBuffer; i++)
1630+
{
1631+
buf = &LocalBufferDescriptors[i];
1632+
if (buf->tag.relId.relId == rdesc->rd_id &&
1633+
buf->tag.blockNum >= block)
1634+
{
1635+
if (buf->flags & BM_DIRTY)
1636+
return (-1);
1637+
if (LocalRefCount[i] > 0)
1638+
return (-2);
1639+
buf->tag.relId.relId = InvalidOid;
1640+
}
1641+
}
1642+
return (0);
1643+
}
1644+
1645+
SpinAcquire(BufMgrLock);
1646+
for (i = 0; i < NBuffers; i++)
1647+
{
1648+
buf = &BufferDescriptors[i];
1649+
if (buf->tag.relId.dbId == MyDatabaseId &&
1650+
buf->tag.relId.relId == rdesc->rd_id &&
1651+
buf->tag.blockNum >= block)
1652+
{
1653+
if (buf->flags & BM_DIRTY)
1654+
{
1655+
SpinRelease(BufMgrLock);
1656+
return (-1);
1657+
}
1658+
if (!(buf->flags & BM_FREE))
1659+
{
1660+
SpinRelease(BufMgrLock);
1661+
return (-2);
1662+
}
1663+
BufTableDelete(buf);
1664+
}
1665+
}
1666+
SpinRelease(BufMgrLock);
1667+
return (0);
1668+
}
1669+
16061670
#undef IncrBufferRefCount
16071671
#undef ReleaseBuffer
16081672

0 commit comments

Comments
 (0)