-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(streams): Add support for XTRIM #1337
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
feat(streams): Add support for XTRIM #1337
Conversation
There was a problem hiding this 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
src/server/stream_family.cc
Outdated
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); | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep sure - updated
src/server/stream_family.cc
Outdated
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); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure yep updated
Signed-off-by: Andy Dunstall <[email protected]>
There was a problem hiding this 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 🏎️
Currently testing this 🙏 |
Adds support for XTRIM (#1332)
TrimStrategy
enum given theAddOptsTrim
prefix seems redundant given its always prefixed byTrimStrategy
?OpTrim
which is the same as trimming inOpAdd
(theres a TODO about handling replication copied over fromOpAdd
which seems out of scope for this)XADD
andXTRIM
argument parsing intoParseAddOrTrimArgsOrReply
(which matches how Redis parses the commands given their arguments are very similar)