Re: Incorrect logic in XLogNeedsFlush()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Cc: Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Jeff Davis <pgsql(at)j-davis(dot)com>, 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-18 03:53:40
Message-ID: aMuCRDSgOUGZtLJ-@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 17, 2025 at 09:23:05PM -0400, Melanie Plageman wrote:
> In terms of comments, I think it is best to update the comment above
> XLogNeedsFlush(). Something like :
>
> /*
> - * Test whether XLOG data has been flushed up to (at least) the given position.
> + * Test whether XLOG data has been flushed up to (at least) the given position
> + * or whether the minimum recovery point is updated past the given position.

Okay.

> - * Returns true if a flush is still needed. (It may be that someone else
> - * is already in process of flushing that far, however.)
> + * Returns true if a flush is still needed or if the minimum recovery point
> + * must be updated.

Okay with that as well. Why not if you find that confusing..

> + * It is possible that someone else is already in the process of flushing that
> + * far or updating the minimum recovery point that far.

I am not sure about the value this part brings, considering the
addition with the two other paragraphs.

>> /*
>> @@ -3114,8 +3121,13 @@ XLogNeedsFlush(XLogRecPtr record)
>> * During recovery, we don't flush WAL but update minRecoveryPoint
>> * instead. So "needs flush" is taken to mean whether minRecoveryPoint
>> * would need to be updated.
>> + *
>> + * XLogInsertAllowed() is used as an end-of-recovery checkpoint is
>> + * launched while recovery is still in progress, RecoveryInProgress()
>> + * returning true in this case. This check should be consistent with the
>> + * one in XLogFlush().
>> */
>
> I can't quite parse the wording of the above comment.

Yep. I am missing an "if" here for "is used as, if an
end-of-recovery", but I am coming with simpler, like:
Using XLogInsertAllowed() rather than RecoveryInProgress() matters for
the case of an end-of-recovery checkpoint, where WAL data is flushed.
This check should be consistent with the one in XLogFlush().
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2025-09-18 03:56:44 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message Yugo Nagata 2025-09-18 03:27:49 Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM