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

feat: add HEXPIRE and FIELDEXPIRE #3842

Merged
merged 9 commits into from
Oct 4, 2024

Conversation

NegatioN
Copy link
Contributor

@NegatioN NegatioN commented Oct 1, 2024

Continuation of: #3780
To implement issue: #3027
Here's my suggestion for how to add the FIELDEXPIRE and HEXPIRE commands. I tried to split it up similarly to how FieldTtl does generic operations across set_family and hset_family.

I've not added support for the optional prefixes [NX | XX | GT | LT], as I see few other commands do it, and I also don't really need it. (Can probably be further work?)

Responses from both commands are (per element queried): -2 for non-existing key/field, 0 if ttl is 0, and ttl gets set, normal success=1

I have a few questions at this point:

  1. I might need help with the flags that are set for the given commands. I frankly just set something that seems to work, and compile.
  2. I'm also unsure about the acl-settings for the commands.

Open for comments. Tagging @romange @kostasrim, since you're already familiar with the previous PR.

Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

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

Hi @NegatioN and thaaaank you for your contribution!

I left some comments mostly about adding a couple of test cases, some corner cases and some nits to avoid code duplication :)

Thank you again 🚀 💯

src/server/hset_family.cc Outdated Show resolved Hide resolved
src/server/hset_family.cc Outdated Show resolved Hide resolved
src/server/hset_family.cc Outdated Show resolved Hide resolved
src/server/generic_family.cc Outdated Show resolved Hide resolved
src/facade/cmd_arg_parser.h Outdated Show resolved Hide resolved
src/server/generic_family.cc Outdated Show resolved Hide resolved
src/server/hset_family.cc Outdated Show resolved Hide resolved
src/server/hset_family.cc Outdated Show resolved Hide resolved
src/server/hset_family_test.cc Show resolved Hide resolved
src/server/hset_family.cc Show resolved Hide resolved
@kostasrim
Copy link
Contributor

@NegatioN let me know when you addressed all the comments and I will rereview :)

src/core/compact_object.h Outdated Show resolved Hide resolved
src/core/compact_object.h Outdated Show resolved Hide resolved
@@ -33,6 +33,9 @@ class SetFamily {
static int32_t FieldExpireTime(const DbContext& db_context, const PrimeValue& pv,
std::string_view field);

static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, PrimeValue& pv,
Copy link
Collaborator

Choose a reason for hiding this comment

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

our style guide requires that we pass output variables (pv) last and by pointer.

@@ -29,9 +29,14 @@ class HSetFamily {
static int32_t FieldExpireTime(const DbContext& db_context, const PrimeValue& pv,
std::string_view field);

static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, PrimeValue& pv,
Copy link
Collaborator

Choose a reason for hiding this comment

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

our style guide requires that we pass output variables (pv) last and by pointer.

Copy link
Contributor Author

@NegatioN NegatioN Oct 3, 2024

Choose a reason for hiding this comment

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

Just to clarify, the signature should be like this?

static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, std::string_view key,
                                               CmdArgList values, PrimeValue& pv)

Copy link
Contributor

@kostasrim kostasrim Oct 3, 2024

Choose a reason for hiding this comment

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

I think he wants:

static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, std::string_view key,
                                               CmdArgList values, PrimeValue* pv)

Notice last argument, it's not a reference but a pointer. (That's from our style guide)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also @NegatioN I am fine with the PR once this is addressed. The rest of my comments are NIT.

LGTM! 🚀

@NegatioN
Copy link
Contributor Author

NegatioN commented Oct 3, 2024

@kostasrim I think this is ready for a review again now.

Comment on lines 19 to 23
template <typename O>
static std::vector<long> ExpireElements(void* ptr, const facade::CmdArgList values,
uint32_t ttl_sec) {
O* owner = (O*)ptr;
std::vector<long> res;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
template <typename O>
static std::vector<long> ExpireElements(void* ptr, const facade::CmdArgList values,
uint32_t ttl_sec) {
O* owner = (O*)ptr;
std::vector<long> res;
template <typename DenseSet>
static std::vector<long> ExpireElements(DenseSet* owner, const facade::CmdArgList values,
uint32_t ttl_sec) {
std::vector<long> res;

Copy link
Contributor

Choose a reason for hiding this comment

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

that way you don't need:

  1. To cast a void* to the respective type
  2. You can now call ExpireElements(arg1, arg2) without the <> syntax. (that is, let the compiler automatically deduce this)

@@ -29,9 +29,14 @@ class HSetFamily {
static int32_t FieldExpireTime(const DbContext& db_context, const PrimeValue& pv,
std::string_view field);

static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, PrimeValue& pv,
Copy link
Contributor

@kostasrim kostasrim Oct 3, 2024

Choose a reason for hiding this comment

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

I think he wants:

static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, std::string_view key,
                                               CmdArgList values, PrimeValue* pv)

Notice last argument, it's not a reference but a pointer. (That's from our style guide)


OpResult<vector<long>> result = cntx->transaction->ScheduleSingleHopT(std::move(cb));
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());
if (result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a function but its fine :)

@NegatioN
Copy link
Contributor Author

NegatioN commented Oct 3, 2024

@kostasrim Done

@kostasrim
Copy link
Contributor

LGTM and thank you for the contribution @NegatioN

@NegatioN
Copy link
Contributor Author

NegatioN commented Oct 4, 2024

btw I have no access to merge the PR, so someone else has to do that for me @kostasrim :)
I want to say thanks for the good feedback from both of you as well, and for staying patient with me even though I have near zero c++ experience.
It's been a fun exercise :)

@kostasrim kostasrim merged commit 0f972a0 into dragonflydb:main Oct 4, 2024
9 checks passed
@romange
Copy link
Collaborator

romange commented Oct 4, 2024

I must say it was a pretty good PR for Zero C++ experience 😮 😮 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants