aboutsummaryrefslogtreecommitdiff
path: root/src/common/file_utils.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2021-11-24 08:13:10 -0500
committerRobert Haas <rhaas@postgresql.org>2021-11-24 08:13:10 -0500
commite7ea2fa342b008ae97e794b0fa2ee538ddcee3b7 (patch)
treed9a99e08de74b170028e0f364c04cf6546e4cb3d /src/common/file_utils.c
parentf79962d8264b8d205ce45a8aa11d1b37f9592a81 (diff)
downloadpostgresql-e7ea2fa342b008ae97e794b0fa2ee538ddcee3b7.tar.gz
postgresql-e7ea2fa342b008ae97e794b0fa2ee538ddcee3b7.zip
Fix corner-case failure to detect improper timeline switch.
rescanLatestTimeLine() contains a guard against switching to a timeline that forked off from the current one prior to the current recovery point, but that guard does not work if the timeline switch occurs before the first WAL recod (which must be the checkpoint record) is read. Without this patch, an improper timeline switch is therefore possible in such cases. This happens because rescanLatestTimeLine() relies on the global variable EndRecPtr to understand the current position of WAL replay. However, EndRecPtr at this point in the code contains the endpoint of the last-replayed record, not the startpoint or endpoint of the record being replayed now. Thus, before any records have been replayed, it's zero, which causes the sanity check to always pass. To fix, pass down the correct timeline explicitly. The EndRecPtr value we want is the one from the xlogreader, which will be the starting position of the record we're about to try to read, rather than the global variable, which is the ending position of the last record we successfully read. They're usually the same, but not in the corner case described here. No back-patch, because in v14 and earlier branhes, we were using the wrong TLI here as well as the wrong LSN. In master, that was fixed by commit 4a92a1c3d1c361ffb031ed05bf65b801241d7cdd, but that and it's prerequisite patches are too invasive to back-patch for such a minor issue. Patch by me, reviewed by Amul Sul. Discussion: http://postgr.es/m/CA+Tgmoao96EuNeSPd+hspRKcsCddu=b1h-QNRuKfY8VmfNQdfg@mail.gmail.com
Diffstat (limited to 'src/common/file_utils.c')
0 files changed, 0 insertions, 0 deletions