Re: gistGetFakeLSN() can return incorrect LSNs
Tomas Vondra <tomas@vondra.me>
From: Tomas Vondra <tomas@vondra.me>
To: Andres Freund <andres@anarazel.de>, Noah Misch <noah@leadboat.com>
Cc: pgsql-hackers@postgresql.org, Tomas Vondra <tv@fuzzy.cz>,
Peter Geoghegan <pg@bowt.ie>
Date: 2026-03-13T11:12:25Z
Lists: pgsql-hackers
Attachments
- 0001-Use-GetXLogInsertEndRecPtr-in-gistGetFakeLSN.patch (text/x-patch) patch 0001
On 3/5/26 21:25, Andres Freund wrote:
> Hi,
>
> On 2026-03-05 10:52:03 -0800, Noah Misch wrote:
>> On Thu, Mar 05, 2026 at 12:10:11PM -0500, Andres Freund wrote:
>>> Tomas encountered a crash with the index prefetching patchset. One of the
>>> patches included therein is a generalization of the gistGetFakeLSN()
>>> mechanism, which is then used by other indexes as well. That triggered an
>>> occasional, hard to locally reproduce, ERROR or PANIC in CI, about
>>>
>>> ERROR: xlog flush request 0/01BD2018 is not satisfied --- flushed only to 0/01BD2000
>>
>>> To be safe, this code would need to use a version of GetXLogInsertRecPtr()
>>> that does use XLogBytePosToEndRecPtr() instead of XLogBytePosToRecPtr().
>>
>> I agree. Thanks for diagnosing it. Feel free to move forward with that
>> strategy, or let me know if you'd like me to do it.
>
> I'd appreciate if you could do it.
>
Here's a fix for master (and backpatching). It introduces a new function
GetXLogInsertEndRecPtr() and then uses that in gistGetFakeLSN(). I still
need to test this a bit more, but it did fix the issue in our dev branch
(where we saw regular failures). So I'm 99% sure it's fine.
After writing the fix I had the idea to grep for GetXLogInsertRecPtr
calls that might have similar issue (being passed to XLogFlush), and
sure enough walsender does this:
XLogFlush(GetXLogInsertRecPtr());
Which AFAICS has the same issue, right? Funnily enough, this is a very
new call, from 2026/03/06. Before 6eedb2a5fd88 walsender might flush not
far enough, now it may be flushing too far ;-) AFAIK it should call the
same GetXLogInsertEndRecPtr() once we have it.
regards
--
Tomas Vondra
Commits
-
Use GetXLogInsertEndRecPtr in gistGetFakeLSN
- c0ffc725f8b3 14.23 landed
- ce06b5740ef9 15.18 landed
- 4f4025eac0b9 16.14 landed
- 6ef36bb35884 17.10 landed
- 5b3f63a1bf59 18.4 landed
- b1f14c967202 19 (unreleased) landed
-
Skip WAL for new relfilenodes, under wal_level=minimal.
- c6b92041d385 13.0 cited