Commit 10238fad authored by Magnus Hagander's avatar Magnus Hagander

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
parent cc07e06b
...@@ -1370,26 +1370,16 @@ throttle(size_t increment) ...@@ -1370,26 +1370,16 @@ throttle(size_t increment)
if (wait_result & WL_LATCH_SET) if (wait_result & WL_LATCH_SET)
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
} }
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 * As we work with integers, only whole multiple of throttling_sample was
* be done during the next call of this function. * processed. The rest will be done during the next call of this function.
*/ */
throttling_counter %= throttling_sample; throttling_counter %= throttling_sample;
/* Once the (possible) sleep has ended, new period starts. */ /*
if (wait_result & WL_TIMEOUT) * Time interval for the remaining amount and possible next increments
throttled_last += elapsed + sleep; * starts now.
else if (sleep > 0) */
/* Sleep was necessary but might have been interrupted. */ throttled_last = GetCurrentIntegerTimestamp();
throttled_last = GetCurrentIntegerTimestamp();
} }
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