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

Function XLogFileRead

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

* Open a logfile segment for reading (during recovery). * * If source == XLOG_FROM_ARCHIVE, the segment is retrieved from archive. * Otherwise, it's assumed to be already available in pg_wal. */

Source from the content-addressed store, hash-verified

3784 * Otherwise, it's assumed to be already available in pg_wal.
3785 */
3786static int
3787XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
3788 XLogSource source, bool notfoundOk)
3789{
3790 char xlogfname[MAXFNAMELEN];
3791 char activitymsg[MAXFNAMELEN + 16];
3792 char path[MAXPGPATH];
3793 int fd;
3794
3795 XLogFileName(xlogfname, tli, segno, wal_segment_size);
3796
3797 switch (source)
3798 {
3799 case XLOG_FROM_ARCHIVE:
3800 /* Report recovery progress in PS display */
3801 snprintf(activitymsg, sizeof(activitymsg), "waiting for %s",
3802 xlogfname);
3803 set_ps_display(activitymsg);
3804
3805 restoredFromArchive = RestoreArchivedFile(path, xlogfname,
3806 "RECOVERYXLOG",
3807 wal_segment_size,
3808 InRedo);
3809 if (!restoredFromArchive)
3810 return -1;
3811 break;
3812
3813 case XLOG_FROM_PG_WAL:
3814 case XLOG_FROM_STREAM:
3815 XLogFilePath(path, tli, segno, wal_segment_size);
3816 restoredFromArchive = false;
3817 break;
3818
3819 default:
3820 elog(ERROR, "invalid XLogFileRead source %d", source);
3821 }
3822
3823 /*
3824 * If the segment was fetched from archival storage, replace the existing
3825 * xlog segment (if any) with the archival version.
3826 */
3827 if (source == XLOG_FROM_ARCHIVE)
3828 {
3829 KeepFileRestoredFromArchive(path, xlogfname);
3830
3831 /*
3832 * Set path to point at the new file in pg_wal.
3833 */
3834 snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname);
3835 }
3836
3837 fd = BasicOpenFile(path, O_RDONLY | PG_BINARY);
3838 if (fd >= 0)
3839 {
3840 /* Success! */
3841 curFileTLI = tli;
3842
3843 /* Report recovery progress in PS display */

Callers 2

XLogFileReadAnyTLIFunction · 0.85

Calls 7

set_ps_displayFunction · 0.85
BasicOpenFileFunction · 0.85
GetCurrentTimestampFunction · 0.85
RestoreArchivedFileFunction · 0.70
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected