Skip to content

Fix db->expires can't be defragged due to incorrect comparison in the expires stage#14092

Merged
sundb merged 6 commits intoredis:unstablefrom
sundb:fix_expires_defrag
Jun 5, 2025
Merged

Fix db->expires can't be defragged due to incorrect comparison in the expires stage#14092
sundb merged 6 commits intoredis:unstablefrom
sundb:fix_expires_defrag

Conversation

@sundb
Copy link
Copy Markdown
Collaborator

@sundb sundb commented May 30, 2025

This bug was introduced by #13814

When defragmenting db->expires, if the process exits early and db->expires was modified in the meantime (e.g., FLUSHDB), we need to check whether the previously defragmented expires is still the same as the current one when resuming. If they differ, we should abort the current defragmentation of expires.

However, in #13814, I made a mistake by using db->keys and db->expires, as expires will never be defragged.

@sundb sundb added the release-notes indication that this issue needs to be mentioned in the release notes label May 30, 2025
@snyk-io
Copy link
Copy Markdown

snyk-io bot commented May 30, 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)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes the incorrect comparison in the expires defragmentation stage and adjusts related test thresholds.

  • Corrects the conditional in defragStageExpiresKvstore to compare db->expires rather than db->keys
  • Updates unit test parameters (active-defrag-threshold-lower and wait_for_defrag_stop multiplier) to reflect the new behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/defrag.c Use db->expires in the resume check for expires defrag
tests/unit/memefficiency.tcl Lower defrag threshold and adjust stop–wait multiplier

@sundb sundb changed the title Fix incorrect skip of expires defrag due to incorrect expires comparison Fix the incorrect comparison in the expires defragmentation stage May 30, 2025
defragKeysCtx *defrag_keys_ctx = ctx;
redisDb *db = &server.db[defrag_keys_ctx->dbid];
if (db->keys != defrag_keys_ctx->kvstate.kvs) {
if (db->expires != defrag_keys_ctx->kvstate.kvs) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YaacovHazan since the TCL test was added in 8.2, we only need to pick this line of code to 8.0 at that time.

@sundb sundb changed the title Fix the incorrect comparison in the expires defragmentation stage Fix server.expires can't be defragmented due to the incorrect comparison in the expires defragmentation stage Jun 5, 2025
@sundb sundb changed the title Fix server.expires can't be defragmented due to the incorrect comparison in the expires defragmentation stage Fix server.expires can't be defragmented due to the incorrect comparison in the expires stage Jun 5, 2025
@sundb sundb changed the title Fix server.expires can't be defragmented due to the incorrect comparison in the expires stage Fix server.expires can't be defragged due to the incorrect comparison in the expires stage Jun 5, 2025
@sundb sundb changed the title Fix server.expires can't be defragged due to the incorrect comparison in the expires stage Fix server.expires can't be defragged due to incorrect comparison in the expires stage Jun 5, 2025
@sundb sundb changed the title Fix server.expires can't be defragged due to incorrect comparison in the expires stage Fix db->expires can't be defragged due to incorrect comparison in the expires stage Jun 5, 2025
@sundb sundb merged commit 2467eff into redis:unstable Jun 5, 2025
18 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Redis 8.2 Jun 5, 2025
sundb added a commit to YaacovHazan/redis that referenced this pull request Jul 2, 2025
… expires stage (redis#14092)

This bug was introduced by redis#13814

When defragmenting `db->expires`, if the process exits early and
`db->expires` was modified in the meantime (e.g., FLUSHDB), we need to
check whether the previously defragmented expires is still the same as
the current one when resuming. If they differ, we should abort the
current defragmentation of expires.

However, in redis#13814, I made a
mistake by using `db->keys` and `db->expires`, as expires will never be
defragged.
@YaacovHazan YaacovHazan mentioned this pull request Jul 6, 2025
YaacovHazan pushed a commit that referenced this pull request Jul 6, 2025
… expires stage (#14092)

This bug was introduced by #13814

When defragmenting `db->expires`, if the process exits early and
`db->expires` was modified in the meantime (e.g., FLUSHDB), we need to
check whether the previously defragmented expires is still the same as
the current one when resuming. If they differ, we should abort the
current defragmentation of expires.

However, in #13814, I made a
mistake by using `db->keys` and `db->expires`, as expires will never be
defragged.
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
… expires stage (redis#14092)

This bug was introduced by redis#13814

When defragmenting `db->expires`, if the process exits early and
`db->expires` was modified in the meantime (e.g., FLUSHDB), we need to
check whether the previously defragmented expires is still the same as
the current one when resuming. If they differ, we should abort the
current defragmentation of expires.

However, in redis#13814, I made a
mistake by using `db->keys` and `db->expires`, as expires will never be
defragged.
@YaacovHazan YaacovHazan moved this from Todo to Done in Redis 8.0 Backport Sep 29, 2025
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.

4 participants