pgsql: Make XLogFlush() and XLogNeedsFlush() decision-making more consi

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make XLogFlush() and XLogNeedsFlush() decision-making more consi
Date: 2025-09-19 04:49:04
Message-ID: E1uzT3P-001RAm-2n@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make XLogFlush() and XLogNeedsFlush() decision-making more consistent

When deciding which code path to use depending on the state of recovery,
XLogFlush() and XLogNeedsFlush() have been relying on different
criterias:
- XLogFlush() relied on XLogInsertAllowed().
- XLogNeedsFlush() relied on RecoveryInProgress().

Currently, the checkpointer is allowed to insert WAL records while
RecoveryInProgress() returns true for an end-of-recovery checkpoint,
where XLogInsertAllowed() matters. Using RecoveryInProgress() in
XLogNeedsFlush() did not really matter for its existing callers, as the
checkpointer only called XLogFlush(). However, a feature under
discussion, by Melanie Plageman, needs XLogNeedsFlush() to be able to
work in more contexts, the end-of-recovery checkpoint being one.

This commit changes XLogNeedsFlush() to use XLogInsertAllowed() instead
of RecoveryInProgress(), making the checks in both routines more
consistent. While on it, an assertion based on XLogNeedsFlush() is
added at the end of XLogFlush(), triggered when flushing a physical
position (not for the normal recovery patch that checks for updates of
the minimum recovery point). This assertion would fail for example in
the recovery test 015_promotion_pages if XLogNeedsFlush() is changed to
use RecoveryInProgress(). This should be hopefully enough to ensure
that the checks done in both routines remain consistent.

Author: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Co-authored-by: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Reviewed-by: Jeff Davis <pgsql(at)j-davis(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Discussion: https://postgr.es/m/CAAKRu_a1vZRZRWO3_jv_X13RYoqLRVipGO0237g5PKzPa2YX6g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/deb208df4559c922df217354f2c0cb689016a2ed

Modified Files
--------------
src/backend/access/transam/xlog.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2025-09-19 05:03:56 pgsql: Improve few errdetail messages introduced in commit 0d48d393d46.
Previous Message Amit Langote 2025-09-19 02:41:07 pgsql: Fix EPQ crash from missing partition pruning state in EState