Skip to content

Fix incorrect server.cronloops update in defragWhileBlocked() causing timer to run twice as fast#14081

Merged
sundb merged 1 commit intoredis:unstablefrom
sundb:run_with_period
May 27, 2025
Merged

Fix incorrect server.cronloops update in defragWhileBlocked() causing timer to run twice as fast#14081
sundb merged 1 commit intoredis:unstablefrom
sundb:run_with_period

Conversation

@sundb
Copy link
Copy Markdown
Collaborator

@sundb sundb commented May 27, 2025

This bug was introduced in #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 #13995, because it needs to be backport, so use a separate pr repair it.

Reproduce steps

redis/src/server.c

Lines 1496 to 1507 in 6349a7c

run_with_period(5000) {
for (j = 0; j < server.dbnum; j++) {
long long size, used, vkeys;
size = kvstoreBuckets(server.db[j].keys);
used = kvstoreSize(server.db[j].keys);
vkeys = kvstoreSize(server.db[j].expires);
if (used || vkeys) {
serverLog(LL_VERBOSE,"DB %d: %lld keys (%lld volatile) in %lld slots HT.",j,used,vkeys,size);
}
}
}

The above log should be printed every five seconds.

config

activedefrag yes
loglevel debug

before this PR:

164249:M 27 May 2025 15:09:55.522 - DB 0: 100000 keys (0 volatile) in 196608 slots HT.
# internal of 2.5 secs
164249:M 27 May 2025 15:10:00.543 - DB 0: 100000 keys (0 volatile) in 131072 slots HT.

after this PR:

162945:M 27 May 2025 15:08:38.847 - DB 0: 100000 keys (0 volatile) in 131072 slots HT.
# interval of 5 secs
162945:M 27 May 2025 15:08:43.867 - DB 0: 100000 keys (0 volatile) in 131072 slots HT.

@sundb sundb requested a review from guybe7 May 27, 2025 07:14
@snyk-io
Copy link
Copy Markdown

snyk-io bot commented May 27, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@sundb sundb added the release-notes indication that this issue needs to be mentioned in the release notes label May 27, 2025
@sundb sundb merged commit bb23eb0 into redis:unstable May 27, 2025
18 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Redis 8.2 May 27, 2025
YaacovHazan pushed a commit to YaacovHazan/redis that referenced this pull request May 27, 2025
… timer to run twice as fast (redis#14081)

This bug was introduced in
[redis#13814](redis#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 redis#13995, because
it needs to be backport, so use a separate pr repair it.
YaacovHazan pushed a commit that referenced this pull request May 27, 2025
… timer to run twice as fast (#14081)

This bug was introduced in
[#13814](#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 #13995, because
it needs to be backport, so use a separate pr repair it.
@YaacovHazan YaacovHazan moved this from Todo to Done in Redis 8.0 Backport Jun 29, 2025
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
… timer to run twice as fast (redis#14081)

This bug was introduced in
[redis#13814](redis#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 redis#13995, because
it needs to be backport, so use a separate pr repair it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants