Forget the prefetcher's current record in XLogPrefetcherBeginRead() XLogPrefetcherBeginRead() reset the decoder's record queue, but not prefetcher->record, whose block references XLogPrefetcherNextBlock() examines. The next read then continued with the remaining block references of that stale record, before decoding the record at the new read position.
FinishWalRecovery() re-reads the last replayed record to find the end of WAL. When recovery stops at a recovery target, the prefetcher may be part-way through a later record, and if its remaining block references fill up the I/O queue, no record is decoded. This fails an assertion in XLogPrefetcherReadRecord(). Without assertions, the start of the last replayed record silently becomes the end of WAL, the new timeline branches off at the wrong point, and the end-of-recovery checkpoint fails with "xlog flush request ... is not satisfied". The recovery signal file is gone by then, so a restart performs crash recovery past the recovery target. This mostly happens with maintenance_io_concurrency set to 7 or less, and a recovery target shortly before an XLOG_FPI record written by an index build, CLUSTER or similar operation, as such records carry up to XLR_MAX_BLOCK_ID block references that need no I/O. Fix by forgetting the current record in XLogPrefetcherBeginRead(). The other callers run before the redo loop, when there is no current record. Add a TAP test that stops recovery shortly before a multi-block XLOG_FPI record of an SP-GiST index build, with maintenance_io_concurrency = 1. The test uses SP-GiST rather than B-tree, so that it works unchanged in the back branches. B-tree builds before 17 WAL-log each page in a separate XLOG_FPI record with a single block reference, so the prefetcher is never part-way through such a record. Author: Tomas Vondra <[email protected]> Reviewed-by: surya poondla <[email protected]> Reviewed-by: shihao zhong <[email protected]> Reviewed-by: Chao Li <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 15 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/9d92394052773ce52ea2ee39bf9678a8bffe119d Modified Files -------------- src/backend/access/transam/xlogprefetcher.c | 3 + src/test/recovery/meson.build | 1 + .../recovery/t/061_recovery_target_prefetch.pl | 94 ++++++++++++++++++++++ 3 files changed, 98 insertions(+)
