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

Function FlushDatabaseBuffers

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

--------------------------------------------------------------------- * FlushDatabaseBuffers * * This function writes all dirty pages of a database out to disk * (or more accurately, out to kernel disk buffers), ensuring that the * kernel has an up-to-date view of the database. * * Generally, the caller should be holding an appropriate lock to ensure * no other backend is active in t

Source from the content-addressed store, hash-verified

3915 * --------------------------------------------------------------------
3916 */
3917void
3918FlushDatabaseBuffers(Oid dbid)
3919{
3920 int i;
3921 BufferDesc *bufHdr;
3922
3923 /* Make sure we can handle the pin inside the loop */
3924 ResourceOwnerEnlargeBuffers(CurrentResourceOwner);
3925
3926 for (i = 0; i < NBuffers; i++)
3927 {
3928 uint32 buf_state;
3929
3930 bufHdr = GetBufferDescriptor(i);
3931
3932 /*
3933 * As in DropRelFileNodeBuffers, an unlocked precheck should be safe
3934 * and saves some cycles.
3935 */
3936 if (bufHdr->tag.rnode.dbNode != dbid)
3937 continue;
3938
3939 ReservePrivateRefCountEntry();
3940
3941 buf_state = LockBufHdr(bufHdr);
3942 if (bufHdr->tag.rnode.dbNode == dbid &&
3943 (buf_state & (BM_VALID | BM_DIRTY)) == (BM_VALID | BM_DIRTY))
3944 {
3945 PinBuffer_Locked(bufHdr);
3946 AcquireContentLock(bufHdr, LW_SHARED);
3947 FlushBuffer(bufHdr, NULL);
3948 ReleaseContentLock(bufHdr);
3949 UnpinBuffer(bufHdr, true);
3950 }
3951 else
3952 UnlockBufHdr(bufHdr, buf_state);
3953 }
3954}
3955
3956/*
3957 * Flush a previously, shared or exclusively, locked and pinned buffer to the

Callers 1

dbase_redoFunction · 0.85

Calls 8

LockBufHdrFunction · 0.85
PinBuffer_LockedFunction · 0.85
AcquireContentLockFunction · 0.85
FlushBufferFunction · 0.85
ReleaseContentLockFunction · 0.85
UnpinBufferFunction · 0.85

Tested by

no test coverage detected