[PATCH] Account for failed recovery prefetch advice

From: Nitin Jadhav <nitinjadhavpostgres(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Account for failed recovery prefetch advice
Date: 2026-11-09 05:43:01
Message-ID: CAMm1aWY+=Px8BcjN=K5S-THFn4N2p2xmzWbCi+mH27CDLdhk2Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While looking at recovery prefetch failure handling, I noticed that
mdprefetch() discards the errno-style result returned by
FilePrefetch(). As a result, an operating-system read-ahead advice
failure is counted as a successful recovery prefetch and treated as
in-flight prefetch I/O, even though no read-ahead request was issued.

The attached patch propagates the advice result through smgr and the
buffer manager. It preserves smgrprefetch()'s existing boolean result,
which is used during recovery to report a missing relation segment,
and adds an optional error result for the read-ahead operation.

When advice fails, xlogprefetcher now increments a new prefetch_failed
statistic, does not increment the successful prefetch count, and
returns LRQ_NEXT_NO_IO. Consequently, the failed request does not
consume logical I/O depth, and recovery reads the block normally when
redo reaches it. The failure remains nonfatal because prefetch advice
is best-effort.

The patch also adds an injection point and a recovery TAP test that
verifies failure accounting, successful replay after advice failures,
and statistics reset.

Feedback is welcome, particularly on the optional error-result API.

Best Regards,
Nitin Jadhav
Microsoft

Attachment Content-Type Size
v1-0001-Account-for-failed-recovery-prefetch-advice.patch application/octet-stream 21.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Tiwari 2026-11-09 05:47:29 Re: reconsider_full_join_clause fails to consider if COALESCE() arguments are NULL-preserving
Previous Message Tom Lane 2026-11-09 05:41:50 Re: Draft back-branch release notes are up