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

Extract a rand sample helper and support negative sample count in "Set" #2113

Merged
merged 6 commits into from
Feb 26, 2024

Conversation

mapleFU
Copy link
Member

@mapleFU mapleFU commented Feb 23, 2024

This patch:

  1. Unify all logic for random sample
  2. Support negative count during Set::Take
  3. Not call Write during srandmember

src/types/redis_set.cc Outdated Show resolved Hide resolved
@mapleFU mapleFU marked this pull request as draft February 23, 2024 06:16
@mapleFU mapleFU changed the title Support negative count during Set::Take Extract a rand sample helper and support negative sample count in "Set" Feb 23, 2024
@mapleFU mapleFU marked this pull request as ready for review February 23, 2024 15:06
torwig
torwig previously approved these changes Feb 23, 2024
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.
I just wondering whether @PragmaTwice will advise to rename sample_helper.h to something with _util.h suffix like random_util/random_sample_util/sample_util :)

batch->Put(metadata_cf_handle_, ns_key, bytes);
// Avoid to write an empty op-log if just random select some members.
if (!pop) return rocksdb::Status::OK();
// Avoid to write an empty op-log if the set is empty.
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't know whether we can do this optimization, would it affect replication?

if (!s.ok()) {
return s;
}
switch (type) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a dcheck. Previously, code called with append_field_with_index. However, GetAll is already called with "type", so it's not neccessary to clean up or set it again

@mapleFU
Copy link
Member Author

mapleFU commented Feb 24, 2024

cc @git-hulk @PragmaTwice

Copy link

sonarcloud bot commented Feb 24, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
60.0% Coverage on New Code (required ≥ 60%)

See analysis details on SonarCloud

@git-hulk git-hulk requested a review from torwig February 26, 2024 12:39
@PragmaTwice
Copy link
Member

LGTM. I just wondering whether @PragmaTwice will advise to rename sample_helper.h to something with _util.h suffix like random_util/random_sample_util/sample_util :)

I am fine since this file is not in common dir.

@PragmaTwice PragmaTwice merged commit 80ca6b0 into apache:unstable Feb 26, 2024
29 of 30 checks passed
@mapleFU mapleFU deleted the cmd-srand-support-negative branch February 26, 2024 15:02
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