-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Prevent EXISTS from incrementing keyspace hit/miss stats #3986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -901,7 +901,7 @@ void existsCommand(client *c) { | |||||
| int j; | ||||||
|
|
||||||
| for (j = 1; j < c->argc; j++) { | ||||||
| if (lookupKeyReadWithFlags(c->db, c->argv[j], LOOKUP_NOTOUCH)) count++; | ||||||
| if (lookupKeyReadWithFlags(c->db, c->argv[j], LOOKUP_NOTOUCH | LOOKUP_NOSTATS)) count++; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On what adding
So the only behavior at stake is the
Suggested change
|
||||||
| } | ||||||
| addReplyLongLong(c, count); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,6 +67,21 @@ start_server {tags {"keyspace"}} { | |||||||||||||||||||
| append res [r exists newkey] | ||||||||||||||||||||
| } {10} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| test {EXISTS does not update keyspace hits or misses} { | ||||||||||||||||||||
| r set existskey value | ||||||||||||||||||||
| set info [r info stats] | ||||||||||||||||||||
| set hits_before [getInfoProperty $info keyspace_hits] | ||||||||||||||||||||
| set misses_before [getInfoProperty $info keyspace_misses] | ||||||||||||||||||||
| r exists existskey | ||||||||||||||||||||
| r exists nonexistingkey | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the miss-path assertion deterministic. At Line 76, Suggested patch test {EXISTS does not update keyspace hits or misses} {
r set existskey value
+ r del nonexistingkey
set info [r info stats]
set hits_before [getInfoProperty $info keyspace_hits]
set misses_before [getInfoProperty $info keyspace_misses]
r exists existskey
r exists nonexistingkey📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| set info [r info stats] | ||||||||||||||||||||
| set hits_after [getInfoProperty $info keyspace_hits] | ||||||||||||||||||||
| set misses_after [getInfoProperty $info keyspace_misses] | ||||||||||||||||||||
| assert_equal $hits_before $hits_after | ||||||||||||||||||||
| assert_equal $misses_before $misses_after | ||||||||||||||||||||
| r del existskey | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| test {Zero length value in key. SET/GET/EXISTS} { | ||||||||||||||||||||
| r set emptykey {} | ||||||||||||||||||||
| set res [r get emptykey] | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOOKUP_NOSTATSsuppresses thekeyspace_missescounter, but thekeymisskeyspace notification is gated separately onLOOKUP_NONOTIFY(src/db.c:120-121), which is not passed here. So after this changeEXISTSon a missing key still fires aNOTIFY_KEY_MISS(keymiss) event while no longer incrementingkeyspace_misses— the two were previously in lockstep for this command.If the intent is "
EXISTSis not a cache access," the notification arguably should be suppressed too, for consistency with the stats:If firing
keymissforEXISTSis intentional (some clients rely on it for key-tracking/invalidation), then leaving it as-is is fine — but worth confirming, since the divergence is easy to miss.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@valkey-review-bot good catch about the LOOKUP_NONOTIFY. what other implications will there be if we add that one as well?