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

Function CheckArchiveTimeout

src/backend/postmaster/checkpointer.c:617–671  ·  view source on GitHub ↗

* CheckArchiveTimeout -- check for archive_timeout and switch xlog files * * This will switch to a new WAL file and force an archive file write if * meaningful activity is recorded in the current WAL file. This includes most * writes, including just a single checkpoint record, but excludes WAL records * that were inserted with the XLOG_MARK_UNIMPORTANT flag being set (like * snapshots of run

Source from the content-addressed store, hash-verified

615 * records.
616 */
617static void
618CheckArchiveTimeout(void)
619{
620 pg_time_t now;
621 pg_time_t last_time;
622 XLogRecPtr last_switch_lsn;
623
624 if (XLogArchiveTimeout <= 0 || RecoveryInProgress())
625 return;
626
627 now = (pg_time_t) time(NULL);
628
629 /* First we do a quick check using possibly-stale local state. */
630 if ((int) (now - last_xlog_switch_time) < XLogArchiveTimeout)
631 return;
632
633 /*
634 * Update local state ... note that last_xlog_switch_time is the last time
635 * a switch was performed *or requested*.
636 */
637 last_time = GetLastSegSwitchData(&last_switch_lsn);
638
639 last_xlog_switch_time = Max(last_xlog_switch_time, last_time);
640
641 /* Now we can do the real checks */
642 if ((int) (now - last_xlog_switch_time) >= XLogArchiveTimeout)
643 {
644 /*
645 * Switch segment only when "important" WAL has been logged since the
646 * last segment switch (last_switch_lsn points to end of segment
647 * switch occurred in).
648 */
649 if (GetLastImportantRecPtr() > last_switch_lsn)
650 {
651 XLogRecPtr switchpoint;
652
653 /* mark switch as unimportant, avoids triggering checkpoints */
654 switchpoint = RequestXLogSwitch(true);
655
656 /*
657 * If the returned pointer points exactly to a segment boundary,
658 * assume nothing happened.
659 */
660 if (XLogSegmentOffset(switchpoint, wal_segment_size) != 0)
661 elog(DEBUG1, "write-ahead log switch forced (archive_timeout=%d)",
662 XLogArchiveTimeout);
663 }
664
665 /*
666 * Update state in any case, so we don't retry constantly when the
667 * system is idle.
668 */
669 last_xlog_switch_time = now;
670 }
671}
672
673/*
674 * Returns true if an immediate checkpoint request is pending. (Note that

Callers 2

CheckpointerMainFunction · 0.85
CheckpointWriteDelayFunction · 0.85

Calls 4

RecoveryInProgressFunction · 0.85
GetLastSegSwitchDataFunction · 0.85
GetLastImportantRecPtrFunction · 0.85
RequestXLogSwitchFunction · 0.85

Tested by

no test coverage detected