-
Notifications
You must be signed in to change notification settings - Fork 15
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
Added script to gather command info and updated base_routing #143
Conversation
redis/src/cluster_routing.rs
Outdated
| b"XINFO STREAM" | ||
| b"ZDIFF" | ||
| b"ZINTER" | ||
| b"ZINTERCARD" | ||
| b"ZMPOP" |
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.
| b"XINFO STREAM" | |
| b"ZDIFF" | |
| b"ZINTER" | |
| b"ZINTERCARD" | |
| b"ZMPOP" | |
| b"XINFO STREAM" | |
| b"SINTERCARD" | |
| b"ZDIFF" | |
| b"ZINTER" | |
| b"ZINTERCARD" | |
| b"ZMPOP" | |
| b"BZMPOP" |
SINTERCARD
and BZMPOP
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.
@aaron-congo @Yury-Fridlyand
Are you intending to add all the missing commands that have 2nd arg as a key or some specific commands?
Lets make it exhaustive (if you already touching this code) - please implement a script that parses all the jsons in $REDIS_ROOT/src/commands/ and filters the commands that have "key" object at index 1 of "arguments" block, per example of ZDIFF:
"arguments": [ { "name": "numkeys", "type": "integer" }, { "name": "key", "type": "key", "key_spec_index": 0, "multiple": true }, { "name": "withscores", "token": "WITHSCORES", "type": "pure-token", "optional": true } ]
Run this script on the ValKey (https://github.com/valkey-io/valkey/releases/tag/7.2.5) source, so not tot touch the licensed Redis.
Please add this script to the PR - it will form the basis for automatically generate all these hard-coded cases during the compilation in the future
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.
I've added SINTERCARD to SecondArgAfterKeyCount and BZMPOP to ThirdArgAfterKeyCount
@aaron-congo when you open PRs, please try to provide some info on the change in the PR description (not automatically ignoring it). For this instance for example - why this PR is needed? |
redis/src/cluster_routing.rs
Outdated
| b"ZINTER" | ||
| b"ZINTERCARD" | ||
| b"ZMPOP" | ||
| b"ZUNION" => RouteBy::SecondArg, |
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.
| b"ZUNION" => RouteBy::SecondArg, | |
| b"LMPOP" | |
| b"BLMPOP" | |
| b"ZUNION" => RouteBy::SecondArg, |
and also Yurri's additions
please check if FCALL
should be there too
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.
I added the commands Yury requested, LMPOP and ZUNION are now routed to SecondArgAfterKeyCount and BLMPOP is mapped to ThirdArgAfterKeyCount. FCALL is under the Uncategorized section of the script since the key argument is optional. For now I've left it out of the cluster_routing.rs file
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.
From the discussion below I've realized cluster_routing can handle optional keys if there is a numkeys argument before the optional key, so I've updated the script to categorize these cases and moved FCALL to ThirdArgAfterKeyCount
redis/src/cluster_routing.rs
Outdated
| b"XINFO STREAM" | ||
| b"ZDIFF" | ||
| b"ZINTER" | ||
| b"ZINTERCARD" | ||
| b"ZMPOP" |
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.
@aaron-congo @Yury-Fridlyand
Are you intending to add all the missing commands that have 2nd arg as a key or some specific commands?
Lets make it exhaustive (if you already touching this code) - please implement a script that parses all the jsons in $REDIS_ROOT/src/commands/ and filters the commands that have "key" object at index 1 of "arguments" block, per example of ZDIFF:
"arguments": [ { "name": "numkeys", "type": "integer" }, { "name": "key", "type": "key", "key_spec_index": 0, "multiple": true }, { "name": "withscores", "token": "WITHSCORES", "type": "pure-token", "optional": true } ]
Run this script on the ValKey (https://github.com/valkey-io/valkey/releases/tag/7.2.5) source, so not tot touch the licensed Redis.
Please add this script to the PR - it will form the basis for automatically generate all these hard-coded cases during the compilation in the future
@ikolomi I like your idea, but keep in mind that these commands already merged on GLIDE repo and doesn't work properly in transaction. Do we have enough time before GLIDE release to implement that? |
As I see that, a script (aka build script) should parse valkey specs and generate a piece of rust code on compilation stage. Does this meet your expectations @ikolomi? |
Or is the script supposed to just print out the commands that have "key" in position 2 so that they can be manually added from the script output to the file here? |
@aaron-congo @Yury-Fridlyand |
import os | ||
from os.path import join | ||
|
||
"""Valkey command categorizer |
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.
This is a very good work!
I am a bit confused - Dont we want to align the RouteBy::SecondArg case with its output? If I understand correctly the SecondArg commands should be the following 2 sets:
============================
Category: SecondArg commands
Description: Commands with their first key argument at position 2
List of commands in this category:
BITOP
MEMORY USAGE
OBJECT ENCODING
OBJECT FREQ
OBJECT IDLETIME
OBJECT REFCOUNT
PFDEBUG
XGROUP CREATE
XGROUP CREATECONSUMER
XGROUP DELCONSUMER
XGROUP DESTROY
XGROUP SETID
XINFO CONSUMERS
XINFO GROUPS
XINFO STREAM
============================
Category: SecondArgAfterKeyCount commands
Description: Commands with their first key argument at position 2, after a numkeys argument
List of commands in this category:
LMPOP
SINTERCARD
ZDIFF
ZINTER
ZINTERCARD
ZMPOP
ZUNION
So per the script's output - both @Yury-Fridlyand and @shohamazon suggestions on FCALL and BZMPOP are not SecondArg?
In addition, please leverage your awesome script to complete the list - it seems that some commands are missing (e.g. MEMORY USAGE)...
Please merge when done
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.
- FCALL is being categorized by the script into ThirdArgAfterKeyCount, the signature is
FCALL function numkeys [key [key ...]] [arg [arg ...]]
. The key arg is optional, so if a key is provided it will be at position 3. Is ThirdArgAfterKeyCount still the correct category even though the key arg is optional? If not, what category should it be? - BZMPOP is being categorized by the script into ThirdArgAfterKeyCount, I think this is correct as its signature is
BZMPOP timeout numkeys key [key ...] <MIN | MAX> [COUNT count]
- MEMORY USAGE is in the SecondArgs category, you can see it in the output snippet you posted above. I just checked and the output number of commands matches the number of json files
There's just a couple things that I still need to do to complete this PR:
- I'm not sure how to distinguish between commands that are mapped to RouteBy::Random vs RouteBy::Undefined based on their json. For example, AUTH is mapped to Random, how should the script determine this based on its json info (here)?
- Once I add logic to map to the random category after resolving the above question, I'll have to add the outputted commands to their categories in cluster_routing.rs
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.
For FCALL
we need another category, I think. In scope of current PR we can leave a TODO note only.
@barshaul what do you think?
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.
Bar answered my question about the random category on slack, she said to leave them in the uncategorized group since there isn't a good way to classify them based on their json. I've added logic to put the commands with optional key arguments in the Uncategorized section of the output. @ikolomi I've also added the commands to cluster_routing.rs, so this PR should be good to merge once it has approvals.
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.
@aaron-congo @Yury-Fridlyand re. FCALL - we already have a fallback if key count == 0, meaning that if no keys are passed, we will route the request to a random node. So please add FCALL to be mapped to ThirdArgAfterKeyCount
# cluster_routing.rs
RouteBy::ThirdArgAfterKeyCount => {
let key_count = r
.arg_idx(2)
.and_then(|x| std::str::from_utf8(x).ok())
.and_then(|x| x.parse::<u64>().ok())?;
if key_count == 0 {
Some(RoutingInfo::SingleNode(SingleNodeRoutingInfo::Random))
} else {
r.arg_idx(3).map(|key| RoutingInfo::for_key(cmd, key))
}
}
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.
since cluster_routing can handle optional keys if there is a numkeys argument before the optional key, I've updated the script to categorize these cases and have updated FCALL to map to ThirdArgAfterKeyCount, this PR should be good to merge now once it has approvals
Hey @aaron-congo, please fix the tests |
…r in this category
@barshaul @shohamazon would you be able to re-run the workflow? |
ofc |
Issue #, if available:
N/A
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.