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

Fail XREAD[GROUP] if duplicate keys were given #11705

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from

Conversation

guybe7
Copy link
Collaborator

@guybe7 guybe7 commented Jan 11, 2023

Fix #11488 (see discussion there for more details)

When using RESP3, XREAD[GROUP] returns a map, so it can't have duplicate keys.
Instead of breaking the protocol (among other suggestions) we decided to ban using duplicate keys for these commands.

Fix redis#11488 (see discussion there for more deatails)

When using RESP3, XREAD[GROUP] returns a map, so it can't have
duplicate keys.
Instead of breaking the protocol (among other suggestions) we
decided to ban using duplicate keys for these commands.
@@ -2247,6 +2247,17 @@ void xreadCommand(client *c) {
return;
}

for (int i = streams_arg + streams_count; i < c->argc; i++) {
for (int j = i + 1; j < c->argc; j++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small question which might not be super important- does that implies that the command is no longer O(NM) where N=number of keys and M is the number of msgs returned by each key, but rather O(N^2+NM)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, i'll update the json files

Copy link
Member

Choose a reason for hiding this comment

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

considering N is expected to be rather low, maybe it shouldn't be there?
@itamarhaber?

Copy link
Member

Choose a reason for hiding this comment

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

or if it isn't expected to be always rather low, maybe this change is wrong..

Copy link
Collaborator

@ranshid ranshid Jan 12, 2023

Choose a reason for hiding this comment

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

also with the new blocking mechanism we will repeat this when reprocessing... might be able to optimize in case this is run during unblock?
Alternative might also be to keep some bit filter on the keys (like simple bloom filter), but again in the worse case it will still be (N^2)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, we can skip that validation in that case, but in order to do that we'll probably need to add a new flag to the client struct, saying we are reprocessing after unblocking... sounds good?

i'm wondering if there are any other expensive validations/calculations we can skip in other commands... can you please have a quick look?

Copy link
Collaborator

@ranshid ranshid Jan 12, 2023

Choose a reason for hiding this comment

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

I am sure we could spare some checks, but I will argue that every command should have arity check function (could even be generated automatically from json), so we could better way to separate the 2 calls and fail the command on invalid arguments at much earlier stage. However that is a big change, and I guess making this case O(2(N^2)+NM) is not the critical thing.

To you question - the only flag that can currently be used is the CLIENT_UNBLOCKED flag... but that might change in the future

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we restrict this PR to just adding validation for duplicate key access in XREAD[GROUP] and probably file a separate issue/PR for avoiding revalidation during reprocessing ?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, we can.. that way we can maybe handle the re-validation optimization earlier.

@oranagra
Copy link
Member

let's re-consider this, see #11488 (comment)

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Successfully merging this pull request may close these issues.

[BUG] XREAD[GROUP] with RESP3 may return a map with dup keys when user requested the same key twice
5 participants