1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

Reorder XLogNeedsFlush() checks to be more consistent

During recovery, XLogNeedsFlush() checks the minimum recovery LSN point
instead of the flush LSN point.  The same condition checks are used when
updating the minimum recovery point in UpdateMinRecoveryPoint(), but are
written in reverse order.

This commit makes the order of the checks consistent between
XLogNeedsFlush() and UpdateMinRecoveryPoint(), improving the code
clarity.  Note that the second check (as ordered by this commit) relies
on InRecovery, which is true only in the startup process.  So this makes
XLogNeedsFlush() cheaper in the startup process with the first check
acting as a shortcut while doing crash recovery, where
LocalMinRecoveryPoint is an invalid LSN.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Discussion: https://postgr.es/m/aMIHNRTP6Wj6vw1s%40paquier.xyz
This commit is contained in:
Michael Paquier
2025-09-30 09:38:32 +09:00
parent 3cc689f833
commit bb68cde413

View File

@@ -3134,6 +3134,10 @@ XLogNeedsFlush(XLogRecPtr record)
*/ */
if (!XLogInsertAllowed()) if (!XLogInsertAllowed())
{ {
/* Quick exit if already known to be updated or cannot be updated */
if (!updateMinRecoveryPoint || record <= LocalMinRecoveryPoint)
return false;
/* /*
* An invalid minRecoveryPoint means that we need to recover all the * An invalid minRecoveryPoint means that we need to recover all the
* WAL, i.e., we're doing crash recovery. We never modify the control * WAL, i.e., we're doing crash recovery. We never modify the control
@@ -3143,11 +3147,10 @@ XLogNeedsFlush(XLogRecPtr record)
* it has not replayed all WAL available when doing crash recovery. * it has not replayed all WAL available when doing crash recovery.
*/ */
if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint) && InRecovery) if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint) && InRecovery)
{
updateMinRecoveryPoint = false; updateMinRecoveryPoint = false;
/* Quick exit if already known to be updated or cannot be updated */
if (record <= LocalMinRecoveryPoint || !updateMinRecoveryPoint)
return false; return false;
}
/* /*
* Update local copy of minRecoveryPoint. But if the lock is busy, * Update local copy of minRecoveryPoint. But if the lock is busy,