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

Support MINID, NOMKSTREAM and LIMIT options for XADD command #1201

Merged
merged 2 commits into from May 17, 2023

Conversation

Abhra303
Copy link
Contributor

Fixes #1163

XADD command currently doesn't support minid, nomkstream and limit options. This PR aims to support these options.

Additionally, I modified the pre-commit configuration file to correctly exclude multiple files (i.e. src/redis and ci/ directories).

@Abhra303 Abhra303 force-pushed the xadd_opt_support branch 4 times, most recently from 9892972 to 3006b39 Compare May 10, 2023 13:07
@Abhra303
Copy link
Contributor Author

Hey @romange @dranikpg @royjacobson , could you please rerun the tests and review the PR?

@adiholden adiholden self-requested a review May 11, 2023 07:53
Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

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

Great work! Happy to see we're getting support for more and more stream arguments. I've re-run the tests - all passed. Seemed like some internal issue within Github.

Comment on lines 46 to 48
constexpr uint8_t kAddOptsTrimNone = 0;
constexpr uint8_t kAddOptsTrimMaxLen = 1;
constexpr uint8_t kAddOptsTrimMinId = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. This can maybe be an enum inside AddOpts
  2. Instead of using pure numbers we can include the TRIM_STRATEGY defines from redis (move to header before)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, Sure! I think point number 2 is better

Copy link
Contributor

Choose a reason for hiding this comment

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

Those are not exclusive 🙂

Copy link
Contributor Author

@Abhra303 Abhra303 May 14, 2023

Choose a reason for hiding this comment

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

Could not we completely remove these const expressions and directly use the redis library's TRIM_STRATEGY definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I.e. Something like if (add_opts.trim_strategy == TRIM_STRATEGY_MAXLEN && ...?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think yes. enum TrimStrategy {MAX_LEN = TRIM_STRATEGY_MAXLEN, ... = ....} would be the cleanest, but that'll work too. Just that we don't have hard-coded integers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I am going with your suggestion then :)

Comment on lines 79 to 83
for (int i = 0; i < 3; i++) {
Run({"xadd", "key3", "*", "field", "val"});
}
resp = Run({"xadd", "key3", "maxlen", "~", "0", "limit", "1", "*", "field", "val"});
EXPECT_THAT(Run({"xlen", "key3"}), IntArg(4));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please make the limit test a little bit more sophisticated?

Another way to control the amount of work done by the command when using the ~, is the LIMIT clause. When used, it specifies the maximal count of entries that will be evicted

So what should limit 1 do here? It might have no effect because ~ is approximate

although after trimming, the stream may have few tens of additional entries over the threshold.

I'd suggest filling the stream with a few hundreds of entries and then setting a low target for maxlen, so that at least a few dozens will be evicted for sure - and test it. Then do the same, but now call the final xadd with limit and assert that only a few were removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was unsure about the test case of limit. So I used one of the redis's "limit" test case. I think your suggestion is great.

Adding these test cases! Thanks.

Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

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

Great work! Happy to see we're getting support for more and more stream arguments

@adiholden adiholden removed their request for review May 14, 2023 07:57
Pre-commit configuration file can't have two "exclude" key to exclude
multiple directories. As a result, pre-commit hook is modifying the
src/redis/.* contents.

Exclude multiple directories from pre-commit hook correctly.

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
@Abhra303
Copy link
Contributor Author

Oops, seems like I forgot to add the enum class you were suggesting about.

Redis xadd command have nomkstream, minid and limit options to
control the behaviour of xadd command. However dragonfly xadd
command doesn't have support for these options.

Support NOMKSTREAM, MINID and LIMIT options for XADD command.

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
@dranikpg dranikpg merged commit b374947 into dragonflydb:main May 17, 2023
6 checks passed
@Abhra303 Abhra303 deleted the xadd_opt_support branch May 17, 2023 07:47
@royjacobson
Copy link
Contributor

Hi @Abhra303!

I noticed that this PR causes some warnings when compiling:

[19/37] Building CXX object src/server/CMakeFiles/dragonfly_lib.dir/stream_family.cc.o
/home/roy/work/dragonfly/src/server/stream_family.cc: In function ‘facade::OpResult<streamID> dfly::{anonymous}::OpAdd(const dfly::OpArgs&, std::string_view, const dfly::{anonymous}::AddOpts&, facade::CmdArgList)’:
/home/roy/work/dragonfly/src/server/stream_family.cc:543:5: warning: missing initializer for member ‘streamAddTrimArgs::id’ [-Wmissing-field-initializers]
  543 |     };
      |     ^
/home/roy/work/dragonfly/src/server/stream_family.cc:543:5: warning: missing initializer for member ‘streamAddTrimArgs::id_given’ [-Wmissing-field-initializers]
/home/roy/work/dragonfly/src/server/stream_family.cc:543:5: warning: missing initializer for member ‘streamAddTrimArgs::seq_given’ [-Wmissing-field-initializers]
[...]

I'm pretty sure this is an actual bug and not a false positive in this case, since some of the uninitialized members are directly used in the follow up. Could you please take a look at the warnings and fix it?

Thanks!

romange pushed a commit that referenced this pull request Jun 1, 2023
Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
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.

XADD missing NOMKSTREAM and MINID options
3 participants