Skip to content

Modules: In RM_HashSet, add COUNT_ALL flag and set errno#8446

Merged
oranagra merged 4 commits intoredis:unstablefrom
zuiderkwast:modules-hashset-flag
Feb 15, 2021
Merged

Modules: In RM_HashSet, add COUNT_ALL flag and set errno#8446
oranagra merged 4 commits intoredis:unstablefrom
zuiderkwast:modules-hashset-flag

Conversation

@zuiderkwast
Copy link
Contributor

The added flag affects the return value of RM_HashSet() to include
the number of inserted fields, in addition to updated and deleted
fields.

Errno is set on errors, tests are added and documentation updated.

Fixes #6914.

@bjosv
Copy link
Contributor

bjosv commented Feb 4, 2021

Nice! LGTM

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

i haven't reviewed the test.
also i didn't read the discussion that lead to this recently, so please let me know if i'm missing some point or going against something that was already agreed.

src/module.c Outdated
Comment on lines 2977 to 2980
Copy link
Member

Choose a reason for hiding this comment

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

i think the term "inserted" is confusing ("updated" is confusing too).

"updated" in this case means a pre-existing member was updated.
but i think the term can also mean new field that was added (the hash object was updated).
so i think we should make it clear in the docs.

similarly, "inserted" sounds like it only means new fields (excluding pre-existing fields), but the code actually means any field that is "set" (both new, and updates). let's try to come up with a better term, and if not, at least make it very clear in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I interpreted it as "inserts" meaning only new fields, and the new flag COUNT_INSERTS means "count the inserts in addition to the updates".

So yeah, it seems these docs need to be improved. We could also rename the flag. Any suggestion?

Copy link
Member

Choose a reason for hiding this comment

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

@itamarhaber maybe you can come up with a term?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

COUNT_ALL? (meaning inserted, updated/replaced and deleted fields)

Copy link
Member

Choose a reason for hiding this comment

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

ok.. better than INSERTS. IMHO. or we can wait for other suggestions.
p.s. there are other references to "updates" and "inserts" in the text, we need to make sure they don't get out of context.

@yossigo
Copy link
Collaborator

yossigo commented Feb 7, 2021

What are we proposing as a way to write a backwards compatible module?

@oranagra
Copy link
Member

oranagra commented Feb 7, 2021

i don't think we can..
modules that don't care about the error, can just use the return value to know the number of updated fields.
modules that do care, have to check which version of redis the use and only look at errno (or use the new flag) on 6.2 and upwards.

@zuiderkwast
Copy link
Contributor Author

modules that do care, have to check which version of redis the use and only look at errno (or use the new flag) on 6.2 and upwards.

... or set errno = 0 before HashSet and check it again afterwards. Then, if errno == 0 after HashSet returned 0, it must be an old Redis. (It's also quite easy to avoid the errors by doing open-for-write and check-key-type before the call to HashSet.)

@yossigo
Copy link
Collaborator

yossigo commented Feb 8, 2021

@zuiderkwast That would work for error conditions, if REDISMODULE_HASH_COUNT_INSERTS is used and ignored on an older version the same operation would have different non-error return values.

I'm OK with accepting this limitation but we'll need to document it clearly.

@zuiderkwast
Copy link
Contributor Author

@zuiderkwast That would work for error conditions, if REDISMODULE_HASH_COUNT_INSERTS is used and ignored on an older version the same operation would have different non-error return values.

I'm OK with accepting this limitation but we'll need to document it clearly.

Good, I agree. I mentioned (added in Redis 6.2) for both the flag and errno. Do you have any more suggestion how to document it clearly?

@yossigo
Copy link
Collaborator

yossigo commented Feb 8, 2021

@zuiderkwast I imagine something in the spirit of "NOTICE: The return value semantics of this function is very different between Redis 6.2 and older versions. Modules that use it should determine the Redis version and handle it accordingly."

@oranagra oranagra changed the title Modules: In RM_HashSet, add COUNT_INSERTS flag and set errno Modules: In RM_HashSet, add COUNT_ALL flag and set errno Feb 8, 2021
@oranagra
Copy link
Member

oranagra commented Feb 8, 2021

@redis/core-team please approve small module API change to allow modules to make sense of the return value of RM_HashSet

@oranagra oranagra added approval-needed Waiting for core team approval to be merged release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus labels Feb 8, 2021
oranagra
oranagra previously approved these changes Feb 8, 2021
The added flag affects the return value of RM_HashSet() to include
the number of inserted fields, in addition to updated and deleted
fields.

Errno is set on errors, tests are added and documentation updated.

Fixes redis#6914.
@itamarhaber
Copy link
Member

@oranagra oranagra merged commit 0bc8c9c into redis:unstable Feb 15, 2021
@zuiderkwast zuiderkwast deleted the modules-hashset-flag branch February 15, 2021 09:55
@oranagra oranagra mentioned this pull request Feb 22, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Mar 2, 2021
The added flag affects the return value of RM_HashSet() to include
the number of inserted fields, in addition to updated and deleted
fields.

errno is set on errors, tests are added and documentation updated.
@zuiderkwast zuiderkwast mentioned this pull request Sep 14, 2021
52 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis module RM_HashSet() return confusing 0 for hash creation

5 participants