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:
debing.sun
2025-05-27 17:14:06 +08:00
committed by GitHub
parent 6349a7c4f9
commit bb23eb0b01
2 changed files with 6 additions and 6 deletions
-6
View File
@@ -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);
+6
View File
@@ -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);