|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * 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 $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -99,6 +99,9 @@ static int FlushBuffer(Buffer buffer, bool release);
|
99 | 99 | static void BufferSync(void);
|
100 | 100 | static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld);
|
101 | 101 |
|
| 102 | +/* not static but used by vacuum only ... */ |
| 103 | +int BlowawayRelationBuffers(Relation rdesc, BlockNumber block); |
| 104 | + |
102 | 105 | /* ---------------------------------------------------
|
103 | 106 | * RelationGetBufferWithBuffer
|
104 | 107 | * see if the given buffer is what we want
|
@@ -1603,6 +1606,67 @@ BufferPoolBlowaway()
|
1603 | 1606 |
|
1604 | 1607 | #endif
|
1605 | 1608 |
|
| 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 | + |
1606 | 1670 | #undef IncrBufferRefCount
|
1607 | 1671 | #undef ReleaseBuffer
|
1608 | 1672 |
|
|
0 commit comments