* 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. */
| 3784 | * Otherwise, it's assumed to be already available in pg_wal. |
| 3785 | */ |
| 3786 | static int |
| 3787 | XLogFileRead(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 */ |
no test coverage detected