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

Function pgarch_ArchiverCopyLoop

src/backend/postmaster/pgarch.c:378–499  ·  view source on GitHub ↗

* pgarch_ArchiverCopyLoop * * Archives all outstanding xlogs then returns */

Source from the content-addressed store, hash-verified

376 * Archives all outstanding xlogs then returns
377 */
378static void
379pgarch_ArchiverCopyLoop(void)
380{
381 char xlog[MAX_XFN_CHARS + 1];
382
383 /* force directory scan in the first call to pgarch_readyXlog() */
384 arch_files->arch_files_size = 0;
385
386 /*
387 * loop through all xlogs with archive_status of .ready and archive
388 * them...mostly we expect this to be a single file, though it is possible
389 * some backend will add files onto the list of those that need archiving
390 * while we are still copying earlier archives
391 */
392 while (pgarch_readyXlog(xlog))
393 {
394 int failures = 0;
395 int failures_orphan = 0;
396
397 for (;;)
398 {
399 struct stat stat_buf;
400 char pathname[MAXPGPATH];
401
402 /*
403 * Do not initiate any more archive commands after receiving
404 * SIGTERM, nor after the postmaster has died unexpectedly. The
405 * first condition is to try to keep from having init SIGKILL the
406 * command, and the second is to avoid conflicts with another
407 * archiver spawned by a newer postmaster.
408 */
409 if (ShutdownRequestPending || !PostmasterIsAlive())
410 return;
411
412 /*
413 * Check for barrier events and config update. This is so that
414 * we'll adopt a new setting for archive_command as soon as
415 * possible, even if there is a backlog of files to be archived.
416 */
417 HandlePgArchInterrupts();
418
419 /* can't do anything if no command ... */
420 if (!XLogArchiveCommandSet())
421 {
422 ereport(WARNING,
423 (errmsg("archive_mode enabled, yet archive_command is not set")));
424 return;
425 }
426
427 /*
428 * Since archive status files are not removed in a durable manner,
429 * a system crash could leave behind .ready files for WAL segments
430 * that have already been recycled or removed. In this case,
431 * simply remove the orphan status file and move on. unlink() is
432 * used here as even on subsequent crashes the same orphan files
433 * would get removed, so there is no need to worry about
434 * durability.
435 */

Callers 1

pgarch_MainLoopFunction · 0.85

Calls 9

pgarch_readyXlogFunction · 0.85
PostmasterIsAliveFunction · 0.85
HandlePgArchInterruptsFunction · 0.85
pgarch_archiveXlogFunction · 0.85
pgarch_archiveDoneFunction · 0.85
pgstat_send_archiverFunction · 0.85
statClass · 0.70
errmsgFunction · 0.50
pg_usleepFunction · 0.50

Tested by

no test coverage detected