* pgarch_ArchiverCopyLoop * * Archives all outstanding xlogs then returns */
| 376 | * Archives all outstanding xlogs then returns |
| 377 | */ |
| 378 | static void |
| 379 | pgarch_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 | */ |
no test coverage detected