aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2021-08-16 12:10:22 +0900
committerMichael Paquier <michael@paquier.xyz>2021-08-16 12:10:22 +0900
commite4ba1005c0f7a95e3252f38aee02426117b8e12b (patch)
tree9e4cf3375f5cf2e1c5db80ff39c2dd5555a01a91 /src/backend/access/transam/xlog.c
parent0a208ed63ffe50a8d9d7c0b33996ec01cc4fdef6 (diff)
downloadpostgresql-e4ba1005c0f7a95e3252f38aee02426117b8e12b.tar.gz
postgresql-e4ba1005c0f7a95e3252f38aee02426117b8e12b.zip
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
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index d0ec6a834be..e51a7a749da 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6248,14 +6248,23 @@ 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;
/*
- * 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(),
delayUntil);