Skip to content
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

Merged
merged 7 commits into from
May 9, 2024

Conversation

aaron-congo
Copy link

@aaron-congo aaron-congo commented Apr 29, 2024

Issue #, if available:
N/A

Description of changes:

  • Adds a script that analyzes json info from the valkey commands directory and categorizes commands based on their RouteBy mapping
  • Updates cluster_routing.rs#base_routing with the info obtained from the script
    • Includes adding a RouteBy::SecondArgAfterKeyCount mapping
  • Changes some incorrect mappings based on the script output
    • WAITAOF was mapped to Random but is now mapped to AllPrimaries
    • BITOP was mapped to Undefined but is now mapped to SecondArg
    • MOVE was mapped to Undefined but is now mapped to FirstKey

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines 400 to 414
| b"XINFO STREAM"
| b"ZDIFF"
| b"ZINTER"
| b"ZINTERCARD"
| b"ZMPOP"

Choose a reason for hiding this comment

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

Suggested change
| 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

Copy link

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

Copy link
Author

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

@ikolomi
Copy link

ikolomi commented Apr 30, 2024

@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?

| b"ZINTER"
| b"ZINTERCARD"
| b"ZMPOP"
| b"ZUNION" => RouteBy::SecondArg,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| 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

Copy link
Author

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

Copy link
Author

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

Comment on lines 400 to 414
| b"XINFO STREAM"
| b"ZDIFF"
| b"ZINTER"
| b"ZINTERCARD"
| b"ZMPOP"
Copy link

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

@Yury-Fridlyand
Copy link

@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?

@Yury-Fridlyand
Copy link

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?

@aaron-congo
Copy link
Author

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?

@ikolomi
Copy link

ikolomi commented May 1, 2024

@aaron-congo @Yury-Fridlyand
I meant to just make the script to detect such commands, not integrate into the build process - what i am lacking in this PR is the understanding of the process - did you manually checked the selected commands?
So like i said, if we already touching this part, lets have a automatic detection process, such script should not be difficult to implement - just json parsing

scripts/get_command_info.py Outdated Show resolved Hide resolved
scripts/get_command_info.py Show resolved Hide resolved
import os
from os.path import join

"""Valkey command categorizer
Copy link

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

Copy link
Author

@aaron-congo aaron-congo May 6, 2024

Choose a reason for hiding this comment

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

@ikolomi

  • 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

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?

Copy link
Author

@aaron-congo aaron-congo May 7, 2024

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.

Copy link

@barshaul barshaul May 8, 2024

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))
                }
            }

Copy link
Author

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

@ikolomi ikolomi dismissed their stale review May 6, 2024 13:34

Merge when #143 (comment) is completed

@aaron-congo aaron-congo changed the title Add base_routing for sorted set commands Added script to gather command info and updated base_routing May 7, 2024
@barshaul
Copy link

barshaul commented May 9, 2024

Hey @aaron-congo, please fix the tests

@acarbonetto
Copy link

@barshaul @shohamazon would you be able to re-run the workflow?

@shohamazon
Copy link
Member

@barshaul @shohamazon would you be able to re-run the workflow?

ofc

@shohamazon shohamazon merged commit e28a978 into amazon-contributing:main May 9, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants