Fix incorrect server.cronloops update in defragWhileBlocked() causing timer to run twice as fast (#14081)
This bug was introduced in [#13814](https://github.com/redis/redis/issues/13814), and was found by @guybe7. It incorrectly moved the update of `server.cronloops` from `whileBlockedCron()` to `activeDefragTimeProc()`, causing the cron-based timers to effectively run twice as fast when active defrag is enabled. As a result, memory statistics are not updated during blocked operations. The repair parts from https://github.com/redis/redis/pull/13995, because it needs to be backport, so use a separate pr repair it.
This commit is contained in:
@@ -1554,12 +1554,6 @@ static int activeDefragTimeProc(struct aeEventLoop *eventLoop, long long id, voi
|
||||
monotime endtime = starttime + dutyCycleUs;
|
||||
int haveMoreWork = 1;
|
||||
|
||||
/* Increment server.cronloops so that run_with_period works. */
|
||||
long hz_ms = 1000 / server.hz;
|
||||
int cronloops = (server.mstime - server.blocked_last_cron + (hz_ms - 1)) / hz_ms; /* rounding up */
|
||||
server.blocked_last_cron += cronloops * hz_ms;
|
||||
server.cronloops += cronloops;
|
||||
|
||||
mstime_t latency;
|
||||
latencyStartMonitor(latency);
|
||||
|
||||
|
||||
@@ -1703,6 +1703,12 @@ void whileBlockedCron(void) {
|
||||
if (server.blocked_last_cron >= server.mstime)
|
||||
return;
|
||||
|
||||
/* Increment server.cronloops so that run_with_period works. */
|
||||
long hz_ms = 1000 / server.hz;
|
||||
int cronloops = (server.mstime - server.blocked_last_cron + (hz_ms - 1)) / hz_ms; /* rounding up */
|
||||
server.blocked_last_cron += cronloops * hz_ms;
|
||||
server.cronloops += cronloops;
|
||||
|
||||
mstime_t latency;
|
||||
latencyStartMonitor(latency);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user