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

#319 Fixed Redis Cluster Crossslot Issue #320

Conversation

SouradipPoddar
Copy link
Contributor

@SouradipPoddar SouradipPoddar commented Mar 6, 2023

Description

Issue Link: #319
The issue is occurring while renaming the temporary key with actual key because the hash slot for temporary key (with _tmp suffix) and actual key (without _tmp suffix) should be same. If they are not same, redis will throw an error:

(error) CROSSSLOT Keys in request don't hash to the same slot

To solve this,we need to force the temporary key to be in the same hash slot. We can do this by adding hashtag to the actual part of the temporary key. When the key contains a "{...}" pattern, only the substring between the braces, "{" and "}," is hashed to obtain the hash slot.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Checklist

  • Linter passes correctly
  • Add tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

Does this introduce a breaking change?

  • Yes
  • No

Further comments

This change I have tested in my environment with 3 master node - 3 replica node redis cluster. It is working fine.

@mga-chka
Copy link
Collaborator

mga-chka commented Mar 6, 2023

I'm surprised to see the failure, a better fix would be to see which operation generates the issue and see if we can avoid it because conceptually chproxy doesn't rely on bulk operations and each operation should deal with only one key.

If there is no solution then we could use the one you provide but you should add comments in the code to explain the meaning of the "{}" with a link the redis doc. But I'm afraid your fix wouldn't fix all situation because (again) conceptually we're not doing bulk operations in chproxy so I don't see why you couldn't have a bulk operation from multiple queries happening at the same time.

[edit] looking more at your description, you already said the issue comes during renaming (I'm guessing this one

r.client.Rename(ctxRename, stringKeyTmp, stringKey)
) which is seen as a bulk multikey operation by redis. I don't see how we can avoid this rename so your fix seems the good one.
Just add the comment I asked and we should be able to merge the PR.

@SouradipPoddar
Copy link
Contributor Author

Thank you for the response. I have added the comment as per your suggestion. Please take a look.

@mga-chka
Copy link
Collaborator

mga-chka commented Mar 7, 2023

FYI your fix will be in the next release that should be available before the end of the month

@mga-chka mga-chka merged commit 6833740 into ContentSquare:master Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants