summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2016-12-19 10:11:04 +0100
committerMagnus Hagander <magnus@hagander.net>2016-12-19 10:16:12 +0100
commitf6508827afe76b2c3735a9ce073620e708d60c79 (patch)
treed56cb6f158a299b0ef9aa78a853cf1f896c3d6f1
parent20c27fdfd3af8da68837ab1cbea08100619f91b6 (diff)
Fix base backup rate limiting in presence of slow i/o
When source i/o on disk was too slow compared to the rate limiting specified, the system could end up with a negative value for sleep that it never got out of, which caused rate limiting to effectively be turned off. Discussion: https://postgr.es/m/CABUevEy_-e0YvL4ayoX8bH_Ja9w%2BBHoP6jUgdxZuG2nEj3uAfQ%40mail.gmail.com Analysis by me, patch by Antonin Houska
-rw-r--r--src/backend/replication/basebackup.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 22745b1afea..3c7a092ff21 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -1308,26 +1308,16 @@ throttle(size_t increment)
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
(long) (sleep / 1000));
}
- else
- {
- /*
- * The actual transfer rate is below the limit. A negative value
- * would distort the adjustment of throttled_last.
- */
- wait_result = 0;
- sleep = 0;
- }
/*
- * Only a whole multiple of throttling_sample was processed. The rest will
- * be done during the next call of this function.
+ * As we work with integers, only whole multiple of throttling_sample was
+ * processed. The rest will be done during the next call of this function.
*/
throttling_counter %= throttling_sample;
- /* Once the (possible) sleep has ended, new period starts. */
- if (wait_result & WL_TIMEOUT)
- throttled_last += elapsed + sleep;
- else if (sleep > 0)
- /* Sleep was necessary but might have been interrupted. */
- throttled_last = GetCurrentIntegerTimestamp();
+ /*
+ * Time interval for the remaining amount and possible next increments
+ * starts now.
+ */
+ throttled_last = GetCurrentIntegerTimestamp();
}