--------------------------------------------------------------------- * 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
| 3915 | * -------------------------------------------------------------------- |
| 3916 | */ |
| 3917 | void |
| 3918 | FlushDatabaseBuffers(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 |
no test coverage detected