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

Implement the command hello #881

Merged
merged 10 commits into from
Sep 18, 2022
Merged

Conversation

mapleFU
Copy link
Member

@mapleFU mapleFU commented Sep 16, 2022

This patch tries to fix this issue: #753

It's a WIP because:

  1. I don't know if I need to implement the logic about authentication.
  2. I don't know how to write some returning code like "sentinel", "version"

Also, I update some implementions in Redis::Array, it will suffer from lots of unnecessary memory allocations

@mapleFU
Copy link
Member Author

mapleFU commented Sep 16, 2022

@git-hulk mind take a look? I need some help here

@git-hulk
Copy link
Member

Hi, @mapleFU, many thanks for your contribution.

I don't know if I need to implement the logic about authentication.

Yes, but there's a bit different in Kvrocks since it has NOT username, so we can always ignore the username. For the auth logic can see redis_cmd.cc#L78.

I don't know how to write some returning code like "sentinel", "version"

Can ignore those sentinel fields since we are never running in sentinel mode.

src/redis_cmd.cc Outdated Show resolved Hide resolved
src/redis_reply.cc Outdated Show resolved Hide resolved
src/redis_reply.cc Outdated Show resolved Hide resolved
@mapleFU
Copy link
Member Author

mapleFU commented Sep 17, 2022

@git-hulk Now I extract the setting logic from CommandAuth, and implement it in HELLO.

But I wonder how can I testing hello, and would it be ambigious if setName is called when conn is an admin? And should we update the tokens here? And should I add some extra return values?

src/redis_cmd.cc Outdated Show resolved Hide resolved
@git-hulk
Copy link
Member

But I wonder how can I testing hello

Do you mean where to add the test case? if yes, can do it in gocase/unit/auth

would it be ambigious if setName is called when conn is an admin? And should we update the tokens here? And should I add some extra return values?

I didn't get this point. For SetName will only add an alias name for connection without other side effects. And no need to update any token/password here.

src/redis_cmd.cc Outdated Show resolved Hide resolved
src/redis_cmd.cc Outdated Show resolved Hide resolved
src/redis_reply.cc Outdated Show resolved Hide resolved
@mapleFU mapleFU changed the title [WIP] Implement the command hello Implement the command hello Sep 17, 2022
@mapleFU
Copy link
Member Author

mapleFU commented Sep 17, 2022

Hi, I'm trying to adding unit tests for hello, but here I come cross a problem:

ADD_CMD("hello", -1,  "read-only ok-loading", 0, 0, 0, CommandHello),

After adding the ADD_CMD above, the auth test would failed:

=== RUN   TestAuth
--- FAIL: TestAuth (2.01s)
=== RUN   TestAuth/AUTH_fails_when_a_wrong_password_is_given
    auth_test.go:56: 
        	Error Trace:	/Users/fuxuwei/workspace/CMakeLibs/incubator-kvrocks/tests/gocase/unit/auth/auth_test.go:56
        	Error:      	Error "NOAUTH Authentication required." does not contain "invalid password"
        	Test:       	TestAuth/AUTH_fails_when_a_wrong_password_is_given
    --- FAIL: TestAuth/AUTH_fails_when_a_wrong_password_is_given (0.00s)

=== RUN   TestAuth/Arbitrary_command_gives_an_error_when_AUTH_is_required
    --- PASS: TestAuth/Arbitrary_command_gives_an_error_when_AUTH_is_required (0.00s)
=== RUN   TestAuth/AUTH_succeeds_when_the_right_password_is_given
    auth_test.go:66: 
        	Error Trace:	/Users/fuxuwei/workspace/CMakeLibs/incubator-kvrocks/tests/gocase/unit/auth/auth_test.go:66
        	Error:      	Not equal: 
        	            	expected: string("OK")
        	            	actual  : <nil>(<nil>)
        	Test:       	TestAuth/AUTH_succeeds_when_the_right_password_is_given
    --- FAIL: TestAuth/AUTH_succeeds_when_the_right_password_is_given (0.00s)


Expected :string("OK")
Actual   :<nil>(<nil>)
<Click to see difference>

Even leaving an empty implements in CommandHello, or not changing the logic of CommandAuth, the test would failed. I think maybe I miss some details in redis_cmd, do you have any ideas? @git-hulk

@mapleFU
Copy link
Member Author

mapleFU commented Sep 17, 2022

It will be no problem when i change ADD_CMD("hello" ... to ADD_CMD("HELLO", ... or "ciallo" , which really makes me mad...

@mapleFU
Copy link
Member Author

mapleFU commented Sep 17, 2022

Oh, finally I find out the reason. go-redis will send hello 3 to kvrocks, and it will be filtered by auth checking...

@mapleFU
Copy link
Member Author

mapleFU commented Sep 17, 2022

[TIMEOUT]: clients state report follows.

maybe I should rerun the test?

@git-hulk
Copy link
Member

[TIMEOUT]: clients state report follows.

maybe I should rerun the test?

Yes, this failure isn't caused by the current PR, let's rerun.

@git-hulk git-hulk added the feature type new feature label Sep 18, 2022
Copy link
Member

@tanruixiang tanruixiang left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution.

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.

LGTM

@git-hulk
Copy link
Member

Thanks all, will merge this PR after the CI becomes green.

@mapleFU
Copy link
Member Author

mapleFU commented Sep 18, 2022

@git-hulk it's able to be merged now (*^3^)

@git-hulk git-hulk merged commit 231f750 into apache:unstable Sep 18, 2022
@git-hulk
Copy link
Member

Thanks @mapleFU again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature type new feature release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants