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 <melanieplage...@gmail.com>
Co-authored-by: Dilip Kumar <dilipbal...@gmail.com>
Reviewed-by: Jeff Davis <pg...@j-davis.com>
Reviewed-by: Chao Li <li.evan.c...@gmail.com>
Reviewed-by: Michael Paquier <mich...@paquier.xyz>
Discussion: 
https://postgr.es/m/caakru_a1vzrzrwo3_jv_x13ryoqlrvipgo0237g5pkzpa2y...@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(-)

Reply via email to