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

Add the support of the LCS command #2116

Merged
merged 19 commits into from
Mar 3, 2024
Merged

Conversation

JoverZhang
Copy link
Contributor

@JoverZhang JoverZhang commented Feb 25, 2024

Close #1955

src/commands/cmd_string.cc Outdated Show resolved Hide resolved
@JoverZhang JoverZhang marked this pull request as ready for review February 26, 2024 13:57
Copy link
Member

@jihuayu jihuayu left a comment

Choose a reason for hiding this comment

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

Thank you @JoverZhang, wonderful algorithm.
I think it's not good to put so much logic in the commander.
Would it be better to move the specific logic to redis::String? @git-hulk

tests/gocase/unit/type/strings/strings_test.go Outdated Show resolved Hide resolved
src/server/redis_request.cc Outdated Show resolved Hide resolved
src/commands/cmd_string.cc Outdated Show resolved Hide resolved
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

I didn't review the logic for response, just some few comments

src/commands/cmd_string.cc Outdated Show resolved Hide resolved
src/commands/cmd_string.cc Outdated Show resolved Hide resolved
src/commands/cmd_string.cc Outdated Show resolved Hide resolved
@jihuayu
Copy link
Member

jihuayu commented Feb 27, 2024

Can someone confirm whether this logic is correct? I am also unable to determine it.
Alternatively, can we ignore whether the algorithm is correct and fix it when a bug arises?

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

General LGTM. Just some few nits

@jihuayu Actually I think this impl works(Since it's code it's similiar with Redis' impl). However, I think the most important thing is prevent malicious user from using lcs to attack the system, or lcs making the server crash...

src/server/redis_request.h Outdated Show resolved Hide resolved
src/commands/cmd_string.cc Outdated Show resolved Hide resolved
src/commands/cmd_string.cc Outdated Show resolved Hide resolved
Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

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

As mentioned by @jihuayu, the implementation of the algorithm should be put into redis_string.cc instead of cmd_string.cc.

@JoverZhang
Copy link
Contributor Author

As mentioned by @jihuayu, the implementation of the algorithm should be put into redis_string.cc instead of cmd_string.cc.

Understood, I have moved the algorithm to redis_string.cc as suggested. Please review the implementation and let me know if any further modifications are required.

@JoverZhang JoverZhang requested a review from git-hulk March 1, 2024 10:24
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

General LGTM

src/types/redis_string.cc Outdated Show resolved Hide resolved
src/types/redis_string.cc Outdated Show resolved Hide resolved

struct StringLCSIdxResult {
// Matched ranges.
std::list<StringLCSMatchedRange> matches;
Copy link
Member

Choose a reason for hiding this comment

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

Though I don't think performance of LCS it's important, I think deque or vector ( using vector without pop_front) would be better here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, deque or vector is better here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank. I have modified this to use the vector.

Initially, I hadn't used the vector because I was concerned that a very large vector would significantly increase memory usage when building the output at the end.
However, I forgot that dp actually frees up more memory space at the end of string_db.LCS().

mapleFU
mapleFU previously approved these changes Mar 3, 2024
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

LGTM

src/types/redis_string.cc Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Mar 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
9.4% Duplication on New Code (required ≤ 5%)

See analysis details on SonarCloud

@PragmaTwice PragmaTwice merged commit 8a4457a into apache:unstable Mar 3, 2024
29 of 30 checks passed
@PragmaTwice
Copy link
Member

Thank you for your contribution!

@JoverZhang JoverZhang deleted the lcs branch March 3, 2024 12:46
@jihuayu
Copy link
Member

jihuayu commented Mar 3, 2024

Hi @JoverZhang, can you add this command to our docs?
You can set Since Version with unstable.
https://kvrocks.apache.org/docs/supported-commands#string-commands

@JoverZhang
Copy link
Contributor Author

Hi @JoverZhang, can you add this command to our docs? You can set Since Version with unstable. https://kvrocks.apache.org/docs/supported-commands#string-commands

Okay, I added it.
apache/kvrocks-website#208

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.

Add support of the command LCS
5 participants