* BufferSync -- Write out all dirty buffers in the pool. * * This is called at checkpoint time to write out all dirty shared buffers. * The checkpoint request flags should be passed in. If CHECKPOINT_IMMEDIATE * is set, we disable delays between writes; if CHECKPOINT_IS_SHUTDOWN, * CHECKPOINT_END_OF_RECOVERY or CHECKPOINT_FLUSH_ALL is set, we write even * unlogged buffers, which are otherwi
| 2057 | * currently have no effect here. |
| 2058 | */ |
| 2059 | static void |
| 2060 | BufferSync(int flags) |
| 2061 | { |
| 2062 | uint32 buf_state; |
| 2063 | int buf_id; |
| 2064 | int num_to_scan; |
| 2065 | int num_spaces; |
| 2066 | int num_processed; |
| 2067 | int num_written; |
| 2068 | CkptTsStatus *per_ts_stat = NULL; |
| 2069 | Oid last_tsid; |
| 2070 | binaryheap *ts_heap; |
| 2071 | int i; |
| 2072 | int mask = BM_DIRTY; |
| 2073 | WritebackContext wb_context; |
| 2074 | |
| 2075 | /* Make sure we can handle the pin inside SyncOneBuffer */ |
| 2076 | ResourceOwnerEnlargeBuffers(CurrentResourceOwner); |
| 2077 | |
| 2078 | /* |
| 2079 | * Unless this is a shutdown checkpoint or we have been explicitly told, |
| 2080 | * we write only permanent, dirty buffers. But at shutdown or end of |
| 2081 | * recovery, we write all dirty buffers. |
| 2082 | */ |
| 2083 | if (!((flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY | |
| 2084 | CHECKPOINT_FLUSH_ALL)))) |
| 2085 | mask |= BM_PERMANENT; |
| 2086 | |
| 2087 | /* |
| 2088 | * Loop over all buffers, and mark the ones that need to be written with |
| 2089 | * BM_CHECKPOINT_NEEDED. Count them as we go (num_to_scan), so that we |
| 2090 | * can estimate how much work needs to be done. |
| 2091 | * |
| 2092 | * This allows us to write only those pages that were dirty when the |
| 2093 | * checkpoint began, and not those that get dirtied while it proceeds. |
| 2094 | * Whenever a page with BM_CHECKPOINT_NEEDED is written out, either by us |
| 2095 | * later in this function, or by normal backends or the bgwriter cleaning |
| 2096 | * scan, the flag is cleared. Any buffer dirtied after this point won't |
| 2097 | * have the flag set. |
| 2098 | * |
| 2099 | * Note that if we fail to write some buffer, we may leave buffers with |
| 2100 | * BM_CHECKPOINT_NEEDED still set. This is OK since any such buffer would |
| 2101 | * certainly need to be written for the next checkpoint attempt, too. |
| 2102 | */ |
| 2103 | num_to_scan = 0; |
| 2104 | for (buf_id = 0; buf_id < NBuffers; buf_id++) |
| 2105 | { |
| 2106 | BufferDesc *bufHdr = GetBufferDescriptor(buf_id); |
| 2107 | |
| 2108 | /* |
| 2109 | * Header spinlock is enough to examine BM_DIRTY, see comment in |
| 2110 | * SyncOneBuffer. |
| 2111 | */ |
| 2112 | buf_state = LockBufHdr(bufHdr); |
| 2113 | |
| 2114 | /* |
| 2115 | * Temp tables in Cloudberry use shared buffers. Filter buffers |
| 2116 | * belonging to temp tables out during checkpoint. |
no test coverage detected