postgres.git / summary / log / commit / refs

commit    024fd44e0566fe2db264aaa3c6d45d0dfdd30b60
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Mon Aug 16 03:12:02 2021 +0000
First released in: 15.0, 9.6.24, 10.19, 11.14, 12.9, 13.5, 14.0

    Refresh apply delay on reload of recovery_min_apply_delay at recovery
    
    This commit ensures that the wait interval in the replay delay loop
    waiting for an amount of time defined by recovery_min_apply_delay is
    correctly handled on reload, recalculating the delay if this GUC value
    is updated, based on the timestamp of the commit record being replayed.
    
    The previous behavior would be problematic for example with replay
    still waiting even if the delay got reduced or just cancelled.  If the
    apply delay was increased to a larger value, the wait would have just
    respected the old value set, finishing earlier.
    
    Author: Soumyadeep Chakraborty, Ashwin Agrawal
    Reviewed-by: Kyotaro Horiguchi, Michael Paquier
    Discussion: https://postgr.es/m/CAE-ML+93zfr-HLN8OuxF0BjpWJ17O5dv1eMvSE5jsj9jpnAXZA@mail.gmail.com
    Backpatch-through: 9.6


src/backend/access/transam/xlog.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 056d5ca9bae..a67304b2308 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6094,12 +6094,22 @@ recoveryApplyDelay(XLogReaderState *record) { ResetLatch(&XLogCtl->recoveryWakeupLatch); - /* might change the trigger file's location */ + /* + * This might change recovery_min_apply_delay or the trigger file's + * location. + */ HandleStartupProcInterrupts(); if (CheckForStandbyTrigger()) break; + /* + * Recalculate recoveryDelayUntilTime as recovery_min_apply_delay + * could have changed while waiting in this loop. + */ + recoveryDelayUntilTime = + TimestampTzPlusMilliseconds(xtime, recovery_min_apply_delay); + /* * Wait for difference between GetCurrentTimestamp() and * recoveryDelayUntilTime [parent: 7915a9515cfb]