Skip to content

Conversation

andydunstall
Copy link
Contributor

@andydunstall andydunstall commented Jun 2, 2023

Adds support for XTRIM (#1332)

  • Renames TrimStrategy enum given the AddOptsTrim prefix seems redundant given its always prefixed by TrimStrategy?
  • Adds OpTrim which is the same as trimming in OpAdd (theres a TODO about handling replication copied over from OpAdd which seems out of scope for this)
  • Refactors XADD and XTRIM argument parsing into ParseAddOrTrimArgsOrReply (which matches how Redis parses the commands given their arguments are very similar)

@romange romange requested a review from dranikpg June 2, 2023 07:30
dranikpg
dranikpg previously approved these changes Jun 2, 2023
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.

Looks solid 👍🏻 But I think we can re-use some of the existing stuff to shrink the implementation significantly

Comment on lines 1059 to 1081
int64_t deleted = 0;
if (!opts.limit) {
if (opts.trim_strategy == TrimStrategy::kMaxLen) {
/* Notify xtrim event if needed. */
deleted = streamTrimByLength(s, opts.max_len, opts.trim_approx);
// TODO: when replicating, we should propagate it as exact limit in case of trimming.
} else if (opts.trim_strategy == TrimStrategy::kMinId) {
deleted = streamTrimByID(s, opts.minid.val, opts.trim_approx);
}
} else {
streamAddTrimArgs trim_args = {};
trim_args.trim_strategy = static_cast<int>(opts.trim_strategy);
trim_args.approx_trim = opts.trim_approx;
trim_args.limit = opts.limit;

if (opts.trim_strategy == TrimStrategy::kMaxLen) {
trim_args.maxlen = opts.max_len;
} else if (opts.trim_strategy == TrimStrategy::kMinId) {
trim_args.minid = opts.minid.val;
}
deleted = streamTrim(s, &trim_args);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it the same as in OpAdd? I think we can unite it in a common trim function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep sure - updated

Comment on lines 1126 to 1142
if (opts.trim_strategy != TrimStrategy::kNone) {
(*cntx)->SendError("MAXLEN and MINID options at the same time are not compatible",
kSyntaxErr);
return std::nullopt;
}

id_indx++;
arg = ArgS(args, id_indx);
if (add_opts.trim_strategy == TrimStrategy::kAddOptsTrimMaxLen &&
!absl::SimpleAtoi(arg, &add_opts.max_len)) {
return (*cntx)->SendError(kSyntaxErr);
if (remaining_args >= 2 && arg == "~") {
opts.trim_approx = true;
id_indx++;
arg = ArgS(args, id_indx);
} else if (remaining_args >= 2 && arg == "=") {
opts.trim_approx = false;
id_indx++;
arg = ArgS(args, id_indx);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Its the same as above, except for the three lines below. I think we can handle MAXLEN and MINID within one branch by differentiating those two cases only at the very end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure yep updated

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.

Fine, now its not spread out or duplicated. One step closer to running bull 🏎️

@romange romange merged commit cde6adb into dragonflydb:main Jun 2, 2023
@ThatOneCalculator
Copy link

Currently testing this 🙏

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