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 BZMPOP command #1490

Merged
merged 13 commits into from
Jun 18, 2023
Merged

Conversation

Yangsx-1
Copy link
Contributor

Close #1445
This PR add supports of bzmpop, bzpopmax, bzpopmin command like Redis.
And I also add some tests for these three commands.
(It's my first PR for kvrocks, there maybe something i didn't recognize. I'm very glad to revise it if there is something wrong.)

@torwig
Copy link
Contributor

torwig commented Jun 11, 2023

@Yangsx-1 You can use the ./x.py format command before committing the code to avoid errors during CI.

@Yangsx-1
Copy link
Contributor Author

@Yangsx-1 You can use the ./x.py format command before committing the code to avoid errors during CI.

Thanks, fixed.

@Yangsx-1
Copy link
Contributor Author

1686471961296
It seems like other things wrong? And it didn't happen in my forked repo's workflow.

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.

Thanks for your contribution!

I notice there are some duplicated code segments, could you try to refactor to avoid these
trivially repeated code?

@Yangsx-1
Copy link
Contributor Author

Thanks for your contribution!

I notice there are some duplicated code segments, could you try to refactor to avoid these trivially repeated code?

OK, i'll try, but it may need some time, i'm a little busy these days.

@PragmaTwice
Copy link
Member

PragmaTwice commented Jun 11, 2023

1686471961296 It seems like other things wrong? And it didn't happen in my forked repo's workflow.

It looks to be a false positive of ThreadSanitizer about TBB. Dont worry.

@Yangsx-1
Copy link
Contributor Author

Thanks for your contribution!

I notice there are some duplicated code segments, could you try to refactor to avoid these trivially repeated code?

Refactored.

src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
return {Status::BlockingCmd};
}

rocksdb::Status TryPopFromZset() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, the function pops from multiple sorted sets which is not expressed by its name. And, except for popping elements, it sends a reply. It's better to separate concerns: pop and return elements in one function and then analyze (if something was popped/if the mode is blocking/etc) and send the response in another function. Let the function do just one thing.

src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
src/commands/cmd_zset.cc Outdated Show resolved Hide resolved
PragmaTwice
PragmaTwice previously approved these changes Jun 16, 2023
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.

Looks good to me with a glance. See if @torwig has more detailed review : )

@Yangsx-1
Copy link
Contributor Author

@torwig Is there anything i need to modify? :)

@torwig
Copy link
Contributor

torwig commented Jun 17, 2023

@Yangsx-1 Right now I don't know :) I'll have a look at the code later.

@torwig
Copy link
Contributor

torwig commented Jun 17, 2023

@Yangsx-1 I made a PR with my changes to your branch. You can approve it and merge so they should be visible here.

@Yangsx-1
Copy link
Contributor Author

@Yangsx-1 I made a PR with my changes to your branch. You can approve it and merge so they should be visible here.

Thanks for your patience and modification!

@torwig torwig requested a review from PragmaTwice June 17, 2023 18:34
Copy link
Contributor

@torwig torwig 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, merging...

@git-hulk git-hulk merged commit 7016bb6 into apache:unstable Jun 18, 2023
@git-hulk
Copy link
Member

Thanks for @Yangsx-1 contribution, you can add the command in https://github.com/apache/incubator-kvrocks-website/blob/main/docs/supported-commands.md if you like. Also thanks for the great review comments from @torwig and @PragmaTwice.

@Yangsx-1 Yangsx-1 deleted the add-BZMPOP branch June 20, 2023 03:18
enjoy-binbin added a commit to enjoy-binbin/kvrocks that referenced this pull request Jul 5, 2023
We did not check for repeated parameters before, so the
following code is executable:
```
127.0.0.1:6666> zmpop 1 zset min max
(nil)
127.0.0.1:6666> zmpop 1 zset min count 10 count 100
(nil)
127.0.0.1:6666> zmpop 1 zset min min max max min
(nil)
127.0.0.1:6666> zmpop 1 zset min count 10 count 100 max
(nil)
127.0.0.1:6666> bzmpop 0.1 1 zset min max
(nil)
127.0.0.1:6666> bzmpop 0.1 1 zset min count 1 count 10
(nil)
```

Now we don't allow duplicate parameters (throw a syntax error):
```
127.0.0.1:6666> zmpop 1 zset min max
(error) ERR syntax error
127.0.0.1:6666> zmpop 1 zset min count 10 count 100
(error) ERR syntax error
127.0.0.1:6666> zmpop 1 zset min min max max min
(error) ERR syntax error
127.0.0.1:6666> zmpop 1 zset min count 10 count 100 max
(error) ERR syntax error
127.0.0.1:6666> bzmpop 0.1 1 zset min max
(error) ERR syntax error
127.0.0.1:6666> bzmpop 0.1 1 zset min count 1 count 10
(error) ERR syntax error
```

Also added some tests to cover these wrong error paths.
Refs: ZMPOP was added in apache#1468 and BZMPOP was added in apache#1490.
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 the support of the BZMPOP command
5 participants