Commit f83d80ea authored by Michael Paquier's avatar Michael Paquier

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
parent 4ffbd55d
...@@ -6205,14 +6205,23 @@ recoveryApplyDelay(XLogReaderState *record) ...@@ -6205,14 +6205,23 @@ recoveryApplyDelay(XLogReaderState *record)
{ {
ResetLatch(&XLogCtl->recoveryWakeupLatch); ResetLatch(&XLogCtl->recoveryWakeupLatch);
/* might change the trigger file's location */ /*
* This might change recovery_min_apply_delay or the trigger file's
* location.
*/
HandleStartupProcInterrupts(); HandleStartupProcInterrupts();
if (CheckForStandbyTrigger()) if (CheckForStandbyTrigger())
break; break;
/* /*
* Wait for difference between GetCurrentTimestamp() and delayUntil * Recalculate delayUntil as recovery_min_apply_delay could have
* changed while waiting in this loop.
*/
delayUntil = TimestampTzPlusMilliseconds(xtime, recovery_min_apply_delay);
/*
* Wait for difference between GetCurrentTimestamp() and delayUntil.
*/ */
msecs = TimestampDifferenceMilliseconds(GetCurrentTimestamp(), msecs = TimestampDifferenceMilliseconds(GetCurrentTimestamp(),
delayUntil); delayUntil);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment