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

Function pgarch_MainLoop

src/backend/postmaster/pgarch.c:298–371  ·  view source on GitHub ↗

* pgarch_MainLoop * * Main loop for archiver */

Source from the content-addressed store, hash-verified

296 * Main loop for archiver
297 */
298static void
299pgarch_MainLoop(void)
300{
301 pg_time_t last_copy_time = 0;
302 bool time_to_stop;
303
304 /*
305 * There shouldn't be anything for the archiver to do except to wait for a
306 * signal ... however, the archiver exists to protect our data, so she
307 * wakes up occasionally to allow herself to be proactive.
308 */
309 do
310 {
311 ResetLatch(MyLatch);
312
313 /* When we get SIGUSR2, we do one more archive cycle, then exit */
314 time_to_stop = ready_to_stop;
315
316 /* Check for barrier events and config update */
317 HandlePgArchInterrupts();
318
319 /*
320 * If we've gotten SIGTERM, we normally just sit and do nothing until
321 * SIGUSR2 arrives. However, that means a random SIGTERM would
322 * disable archiving indefinitely, which doesn't seem like a good
323 * idea. If more than 60 seconds pass since SIGTERM, exit anyway, so
324 * that the postmaster can start a new archiver if needed.
325 */
326 if (ShutdownRequestPending)
327 {
328 time_t curtime = time(NULL);
329
330 if (last_sigterm_time == 0)
331 last_sigterm_time = curtime;
332 else if ((unsigned int) (curtime - last_sigterm_time) >=
333 (unsigned int) 60)
334 break;
335 }
336
337 /* Do what we're here for */
338 pgarch_ArchiverCopyLoop();
339 last_copy_time = time(NULL);
340
341 /*
342 * Sleep until a signal is received, or until a poll is forced by
343 * PGARCH_AUTOWAKE_INTERVAL having passed since last_copy_time, or
344 * until postmaster dies.
345 */
346 if (!time_to_stop) /* Don't wait during last iteration */
347 {
348 pg_time_t curtime = (pg_time_t) time(NULL);
349 int timeout;
350
351 timeout = PGARCH_AUTOWAKE_INTERVAL - (curtime - last_copy_time);
352 if (timeout > 0)
353 {
354 int rc;
355

Callers 1

PgArchiverMainFunction · 0.85

Calls 4

ResetLatchFunction · 0.85
HandlePgArchInterruptsFunction · 0.85
pgarch_ArchiverCopyLoopFunction · 0.85
WaitLatchFunction · 0.85

Tested by

no test coverage detected