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

Function XLogFileReadAnyTLI

src/backend/access/transam/xlog.c:3869–3965  ·  view source on GitHub ↗

* Open a logfile segment for reading (during recovery). * * This version searches for the segment with any TLI listed in expectedTLEs. */

Source from the content-addressed store, hash-verified

3867 * This version searches for the segment with any TLI listed in expectedTLEs.
3868 */
3869static int
3870XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
3871{
3872 char path[MAXPGPATH];
3873 ListCell *cell;
3874 int fd;
3875 List *tles;
3876
3877 /*
3878 * Loop looking for a suitable timeline ID: we might need to read any of
3879 * the timelines listed in expectedTLEs.
3880 *
3881 * We expect curFileTLI on entry to be the TLI of the preceding file in
3882 * sequence, or 0 if there was no predecessor. We do not allow curFileTLI
3883 * to go backwards; this prevents us from picking up the wrong file when a
3884 * parent timeline extends to higher segment numbers than the child we
3885 * want to read.
3886 *
3887 * If we haven't read the timeline history file yet, read it now, so that
3888 * we know which TLIs to scan. We don't save the list in expectedTLEs,
3889 * however, unless we actually find a valid segment. That way if there is
3890 * neither a timeline history file nor a WAL segment in the archive, and
3891 * streaming replication is set up, we'll read the timeline history file
3892 * streamed from the primary when we start streaming, instead of
3893 * recovering with a dummy history generated here.
3894 */
3895 if (expectedTLEs)
3896 tles = expectedTLEs;
3897 else
3898 tles = readTimeLineHistory(recoveryTargetTLI);
3899
3900 foreach(cell, tles)
3901 {
3902 TimeLineHistoryEntry *hent = (TimeLineHistoryEntry *) lfirst(cell);
3903 TimeLineID tli = hent->tli;
3904
3905 if (tli < curFileTLI)
3906 break; /* don't bother looking at too-old TLIs */
3907
3908 /*
3909 * Skip scanning the timeline ID that the logfile segment to read
3910 * doesn't belong to
3911 */
3912 if (hent->begin != InvalidXLogRecPtr)
3913 {
3914 XLogSegNo beginseg = 0;
3915
3916 XLByteToSeg(hent->begin, beginseg, wal_segment_size);
3917
3918 /*
3919 * The logfile segment that doesn't belong to the timeline is
3920 * older or newer than the segment that the timeline started or
3921 * ended at, respectively. It's sufficient to check only the
3922 * starting segment of the timeline here. Since the timelines are
3923 * scanned in descending order in this loop, any segments newer
3924 * than the ending segment should belong to newer timeline and
3925 * have already been read before. So it's not necessary to check
3926 * the ending segment of the timeline here.

Callers 1

Calls 5

readTimeLineHistoryFunction · 0.85
XLogFileReadFunction · 0.85
foreachFunction · 0.50
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected