Skip to content

Fix additional parameter parsing in SCAN#2236

Closed
jackyyyyyssss wants to merge 20 commits intoapache:unstablefrom
jackyyyyyssss:lzl_learning
Closed

Fix additional parameter parsing in SCAN#2236
jackyyyyyssss wants to merge 20 commits intoapache:unstablefrom
jackyyyyyssss:lzl_learning

Conversation

@jackyyyyyssss
Copy link
Copy Markdown
Contributor

@jackyyyyyssss jackyyyyyssss commented Apr 11, 2024

When kvrocks executes a scan command, such as SCAN 0 key match * he 1000, it will change the originally recognized match to a key without reporting any errors. Finally, the value of prefix_ will match all keys, and this command will report an error under normal Redis. Add mandatory matching verification code and use the current test case for testing

@jackyyyyyssss jackyyyyyssss requested a review from git-hulk April 11, 2024 08:17
if (params->count <= 0) {
return {Status::RedisParseErr, errInvalidSyntax};
}
} else if (util::ToLower(args[i]) == "type") {
Copy link
Copy Markdown
Member

@PragmaTwice PragmaTwice Apr 11, 2024

Choose a reason for hiding this comment

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

Please try to imagine what will happen if the input is scan xxx type.

@PragmaTwice PragmaTwice changed the title Fix scan args Fix additional parameter parsing in SCAN Apr 11, 2024
Comment on lines 823 to 825
if (args.size() % 2 != 0) {
return {Status::RedisParseErr, errWrongNumOfArguments};
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am a C++beginner. Thank you very much for your guidance on my code. I have learned a lot

Co-authored-by: Twice <twice@apache.org>
jackyyyyyssss and others added 2 commits April 12, 2024 19:15
Co-authored-by: Twice <twice@apache.org>
Co-authored-by: Twice <twice@apache.org>
@git-hulk
Copy link
Copy Markdown
Member

@jackyyyyyssss CommandSubkeyScanBase should have the same issue which is used for HSCAN/SSCAN/ZSCAN: https://redis.io/docs/latest/commands/sscan/.

@jackyyyyyssss
Copy link
Copy Markdown
Contributor Author

jackyyyyyssss commented Apr 12, 2024

@jackyyyyyssss CommandSubkeyScanBase should have the same issue which is used for HSCAN/SSCAN/ZSCAN: https://redis.io/docs/latest/commands/sscan/.

Okay, can I use different PR for these modifications?

@git-hulk
Copy link
Copy Markdown
Member

@jackyyyyyssss Perhaps you can take a look, it's in the same file and they share the same parse logic except the CommandSubkeyScanBase starts parsing the match/count from the 2nd parameter, and type is not allowed.

@git-hulk
Copy link
Copy Markdown
Member

@jackyyyyyssss Can remove ParseMatchAndCountParam if no place is using it.

Comment on lines +94 to +111
CommandParser parser(args, 1);
key_ = GET_OR_RET(parser.TakeStr());
ParseCursor(GET_OR_RET(parser.TakeStr()));
while (parser.Good()) {
if (parser.EatEqICase("match")) {
prefix_ = GET_OR_RET(parser.TakeStr());
if (!prefix_.empty() && prefix_.back() == '*') {
prefix_ = prefix_.substr(0, prefix_.size() - 1);
} else {
return {Status::RedisParseErr, "currently only key prefix matching is supported"};
}
} else if (parser.EatEqICase("count")) {
limit_ = GET_OR_RET(parser.TakeInt());
if (limit_ <= 0) {
return {Status::RedisParseErr, errInvalidSyntax};
}
} else {
return {Status::RedisParseErr, errWrongNumOfArguments};
Copy link
Copy Markdown
Member

@PragmaTwice PragmaTwice Apr 12, 2024

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@jackyyyyyssss jackyyyyyssss Apr 12, 2024

Choose a reason for hiding this comment

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

I have a question about whether this parsing is written in CommandScanBase, or if both have differences written in their respective places, with the public part written in base. However, if so, what should be the template value for CommandParser as a method parameter? like this
template < typename Iter >
Status ProcessCommonParser(CommandParser &parser) {..}

@jackyyyyyssss
Copy link
Copy Markdown
Contributor Author

@jackyyyyyssss Can remove ParseMatchAndCountParam if no place is using it.

ok

Comment on lines +54 to +55
} else if (parser.EatEqICase("type")) {
// HSCAN SSCAN ZSCAN Will not enter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you think that "HSCAN SSCAN ZSCAN will not enter" this block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe my description is a bit inaccurate. After other commands are added, error prompts will be return

Status Parse(const std::vector<std::string> &args) override {
CommandParser parser(args, 1);
if (util::ToLower(args[0]) != "scan") {
key_ = GET_OR_RET(parser.TakeStr());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be only in CommandSubkeyScanBase.

@PragmaTwice
Copy link
Copy Markdown
Member

I will prepare a patch to succeed this PR.

@jackyyyyyssss
Copy link
Copy Markdown
Contributor Author

I will prepare a patch to succeed this PR.

Can you help me take a look at the optimized version thks

@PragmaTwice
Copy link
Copy Markdown
Member

It's more close. But I think we can save some communication effort by my patch..

I'll make you the co-author of the patch, and hope you can learn some C++ knowledege from my code.

Also, in the next time, please don't forget to write test cases for your patch, as it's mandatory.

@jackyyyyyssss
Copy link
Copy Markdown
Contributor Author

It's more close. But I think we can save some communication effort by my patch..

I'll make you the co-author of the patch, and hope you can learn some C++ knowledege from my code.

Also, in the next time, please don't forget to write test cases for your patch, as it's mandatory.

Thank you for your patient answer

@sonarqubecloud
Copy link
Copy Markdown

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.

4 participants