MCPcopy Create free account
hub / github.com/apache/cloudberry / MarkBufferDirty

Function MarkBufferDirty

src/backend/storage/buffer/bufmgr.c:1680–1728  ·  view source on GitHub ↗

* MarkBufferDirty * * Marks buffer contents as dirty (actual write happens later). * * Buffer must be pinned and exclusive-locked. (If caller does not hold * exclusive lock, then somebody could be in process of writing the buffer, * leading to risk of bad data written to disk.) */

Source from the content-addressed store, hash-verified

1678 * leading to risk of bad data written to disk.)
1679 */
1680void
1681MarkBufferDirty(Buffer buffer)
1682{
1683 BufferDesc *bufHdr;
1684 uint32 buf_state;
1685 uint32 old_buf_state;
1686
1687 if (!BufferIsValid(buffer))
1688 elog(ERROR, "bad buffer ID: %d", buffer);
1689
1690 if (BufferIsLocal(buffer))
1691 {
1692 MarkLocalBufferDirty(buffer);
1693 return;
1694 }
1695
1696 bufHdr = GetBufferDescriptor(buffer - 1);
1697
1698 Assert(BufferIsPinned(buffer));
1699 Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
1700 LW_EXCLUSIVE));
1701
1702 old_buf_state = pg_atomic_read_u32(&bufHdr->state);
1703 for (;;)
1704 {
1705 if (old_buf_state & BM_LOCKED)
1706 old_buf_state = WaitBufHdrUnlocked(bufHdr);
1707
1708 buf_state = old_buf_state;
1709
1710 Assert(BUF_STATE_GET_REFCOUNT(buf_state) > 0);
1711 buf_state |= BM_DIRTY | BM_JUST_DIRTIED;
1712
1713 if (pg_atomic_compare_exchange_u32(&bufHdr->state, &old_buf_state,
1714 buf_state))
1715 break;
1716 }
1717
1718 /*
1719 * If the buffer was not dirty already, do vacuum accounting.
1720 */
1721 if (!(old_buf_state & BM_DIRTY))
1722 {
1723 VacuumPageDirty++;
1724 pgBufferUsage.shared_blks_dirtied++;
1725 if (VacuumCostActive)
1726 VacuumCostBalance += VacuumCostPageDirty;
1727 }
1728}
1729
1730/*
1731 * ReleaseAndReadBuffer -- combine ReleaseBuffer() and ReadBuffer()

Callers 15

heap_force_commonFunction · 0.85
fill_seq_with_dataFunction · 0.85
nextval_internalFunction · 0.85
do_setvalFunction · 0.85
seq_redoFunction · 0.85
SpGistUpdateMetaPageFunction · 0.85
saveNodeLinkFunction · 0.85
addLeafTupleFunction · 0.85
moveLeafsFunction · 0.85
doPickSplitFunction · 0.85
spgAddNodeActionFunction · 0.85

Calls 5

MarkLocalBufferDirtyFunction · 0.85
LWLockHeldByMeInModeFunction · 0.85
pg_atomic_read_u32Function · 0.85
WaitBufHdrUnlockedFunction · 0.85

Tested by

no test coverage detected