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 ZADD options #1022

Merged
merged 35 commits into from
Oct 28, 2022
Merged

Conversation

manchurio
Copy link
Contributor

This closes #1018

Has passed the unit test with go.

@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 21, 2022

You can just run ./x.py format to format the source code rather than manual formatting.

@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 21, 2022

Oh, I notice the cppcheck false alarm. I think you can change --std=c++11 to 17 here: https://github.com/apache/incubator-kvrocks/blob/unstable/x.py#L162

@manchurio

@manchurio
Copy link
Contributor Author

You can just run ./x.py format to format the source code rather than manual formatting.

got it,thanks.

@manchurio
Copy link
Contributor Author

Oh, I notice the cppcheck false alarm. I think you can change --std=c++11 to 17 here: https://github.com/apache/incubator-kvrocks/blob/unstable/x.py#L162

@manchurio

src/commands/redis_cmd.cc:2432:19: warning: Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]
    if (auto it = options.find(option); it != options.end()) {
                  ^

It seems cppcheck wrongly reports @PragmaTwice

@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 21, 2022

It is sad that cppcheck still fail and report a FALSE ALARM.

We will replace cppcheck by clang-tidy later, and I think you can now workaround it by auto iter = ...; if(iter != end()) ...

cc @git-hulk

PragmaTwice and others added 3 commits October 21, 2022 21:23
* Add mailing list to README

* Update .asf.yaml

* Update README.md

Co-authored-by: tison <wander4096@gmail.com>

Co-authored-by: tison <wander4096@gmail.com>
@git-hulk
Copy link
Member

@manchurio Need to use gofmt to format the test case

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.

If you only need to determine whether the key exists, you can use count directly, the iterator is redundant. Also doing this will not trigger an error from cppcheck. (By the way, C++20 has contains to do this thing. )

src/commands/redis_cmd.cc Outdated Show resolved Hide resolved
@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 21, 2022

If you only need to determine whether the key exists, you can use count directly, the iterator is redundant. Also doing this will not trigger an error from cppcheck. (By the way, C++20 has contains to do this thing. )

Hi @tanruixiang,

Actually I like the original code more, since the iterator is used in the true-branch block to avoid a double search (the upper bound is actually not O(1) due to collision, and even O(1) DOES NOT imples no cost).

And I think this change does not improve readability, as the use of iterators is natural and easy to understand in c++. The false positives of cppcheck are entirely due to his own problems, and we should not modify the code logic just for that.

And in my opinion, I prefer just a comment rather than "request for changes" for just a trivial and purely code-smell review message, in order to be nice to new contributors.

@tanruixiang
Copy link
Member

tanruixiang commented Oct 21, 2022

And in my opinion, I prefer just a comment rather than "request for changes" for just a trivial and purely code-smell review message, in order to be nice to new contributors.

Got it, thanks a lot for your suggestion. It should be that I misunderstood this "request for changes". I originally thought that only use "request for changes" can be clicked on github to modify. (Because if someone else suggests a little modification, I prefer to click on github to complete the modification🤣)

@tanruixiang
Copy link
Member

Actually I like the original code more, since the iterator is used in the true-branch block to avoid a double search (the upper bound is actually not O(1) due to collision, and even O(1) DOES NOT imples no cost).

And I think this change does not improve readability, as the use of iterators is natural and easy to understand in c++. The false positives of cppcheck are entirely due to his own problems, and we should not modify the code logic just for that.

Maybe it's my bad habit, I always try not to use iterators in code snippets that are similar to algorithm problems. I will try to use iterators more in the future.

@PragmaTwice
Copy link
Member

And in my opinion, I prefer just a comment rather than "request for changes" for just a trivial and purely code-smell review message, in order to be nice to new contributors.

Got it, thanks a lot for your suggestion. It should be that I misunderstood this "request for changes". I originally thought that only use "request for changes" can be clicked on github to modify. (Because if someone else suggests a little modification, I prefer to click on github to complete the modification🤣)

In the github review page, you can select "comment", "request for changes" or "approve". I think the first option is relatively "milder".

@manchurio manchurio requested a review from tanruixiang October 21, 2022 22:00
@manchurio
Copy link
Contributor Author

@manchurio You can also consider using something like the following to encapsulate the logic with options and eliminate code duplication:

struct ZAddOptions {
  ZAddOptions() {}
  explicit ZAddOptions(uint8_t flags) : flags(flags) {}

  bool IsXX() const { return (flags & kZSetNX) != 0; }
  // other methods to ask if the specific flag was set

  uint8_t flags = 0;
};

Of course, you can add methods like SetXX to encapsulate set operations as well (to not spread bit operations over the codebase).

This refactoring has been completed

@torwig
Copy link
Contributor

torwig commented Oct 24, 2022

@manchurio Thank you, I'll have a look at it as soon as possible.

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.

Hi. Since there is a unified interface to get the flag's status, then we don't need additional variables to store. Even if there is reuse, there is no difference in speed.

src/commands/redis_cmd.cc Outdated Show resolved Hide resolved
src/commands/redis_cmd.cc Outdated Show resolved Hide resolved
src/types/redis_zset.cc Outdated Show resolved Hide resolved
src/types/redis_zset.h Outdated Show resolved Hide resolved
src/types/redis_zset.h Outdated Show resolved Hide resolved
src/types/redis_zset.h Outdated Show resolved Hide resolved
Copy link
Member

@git-hulk git-hulk left a comment

Choose a reason for hiding this comment

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

Overall is good for me, only one comment.

src/commands/redis_cmd.cc Outdated Show resolved Hide resolved
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

@tisonkun tisonkun merged commit 30a0348 into apache:unstable Oct 28, 2022
PragmaTwice added a commit that referenced this pull request Oct 28, 2022
@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 28, 2022

Sorry, touched wrong button. 🤣
The new branch generated by the revert button has been deleted.

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.

Support ZADD options
6 participants