Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1c8ad59

Browse files
committed
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
1 parent 512f27c commit 1c8ad59

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/backend/replication/basebackup.c

+7-17
Original file line numberDiff line numberDiff line change
@@ -1303,26 +1303,16 @@ throttle(size_t increment)
13031303
if (wait_result & WL_LATCH_SET)
13041304
CHECK_FOR_INTERRUPTS();
13051305
}
1306-
else
1307-
{
1308-
/*
1309-
* The actual transfer rate is below the limit. A negative value
1310-
* would distort the adjustment of throttled_last.
1311-
*/
1312-
wait_result = 0;
1313-
sleep = 0;
1314-
}
13151306

13161307
/*
1317-
* Only a whole multiple of throttling_sample was processed. The rest will
1318-
* be done during the next call of this function.
1308+
* As we work with integers, only whole multiple of throttling_sample was
1309+
* processed. The rest will be done during the next call of this function.
13191310
*/
13201311
throttling_counter %= throttling_sample;
13211312

1322-
/* Once the (possible) sleep has ended, new period starts. */
1323-
if (wait_result & WL_TIMEOUT)
1324-
throttled_last += elapsed + sleep;
1325-
else if (sleep > 0)
1326-
/* Sleep was necessary but might have been interrupted. */
1327-
throttled_last = GetCurrentIntegerTimestamp();
1313+
/*
1314+
* Time interval for the remaining amount and possible next increments
1315+
* starts now.
1316+
*/
1317+
throttled_last = GetCurrentIntegerTimestamp();
13281318
}

0 commit comments

Comments
 (0)