Re: Incorrect logic in XLogNeedsFlush()

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Incorrect logic in XLogNeedsFlush()
Date: 2025-09-10 12:41:25
Message-ID: CAAKRu_YB5nEDdW14DEKRwb9sZ+b4d8w-1hA8hE=_AuBhH6=sUg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 10, 2025 at 3:18 AM Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
>
> On Wed, Sep 10, 2025 at 1:59 AM Melanie Plageman
> <melanieplageman(at)gmail(dot)com> wrote:
>
> > Though, it seems like LocalMinRecoveryPoint must be getting
> > incorrectly set elsewhere, otherwise this would have guarded us from
> > examining the control file:
> >
> > if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint) && InRecovery)
> > updateMinRecoveryPoint = false;
> >
> > /* Quick exit if already known to be updated or cannot be updated */
> > if (record <= LocalMinRecoveryPoint || !updateMinRecoveryPoint)
> > return false;
>
> That's not quite right. Before the end-of-recovery checkpoint, the
> InRecovery flag is already set to false. This means that even if
> LocalMinRecoveryPoint is invalid, it won't matter, and
> updateMinRecoveryPoint will not be set to false. Since
> LocalMinRecoveryPoint is 0, the condition if (record <=
> LocalMinRecoveryPoint) will also fail, causing the process to continue
> and read from the ControlFile.

Ah, right, I got turned around. My original investigation showed me
that the checkpointer incorrectly read from the ControlFile when I
added the XLogNeedsFlush() precisely because InRecovery is false
outside of the startup process.

What I want is for it to be safe and accurate to call XLogNeedsFlush()
in any backend (one that might flush WAL, that is).

- Melanie

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Matheus Alcantara 2025-09-10 13:05:21 Re: Proposal: Out-of-Order NOTIFY via GUC to Improve LISTEN/NOTIFY Throughput
Previous Message Andrey Borodin 2025-09-10 12:36:48 Re: Fix inconsistencies with code and beautify xlog structures description and fin hash_xlog.h