cachedb_redis: add ASK redirect handling and fix hash slot calculation#3852
Open
dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
Open
cachedb_redis: add ASK redirect handling and fix hash slot calculation#3852dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
Conversation
Add support for Redis ASK redirects during cluster resharding. When a slot is being migrated between nodes, Redis returns an ASK response instead of MOVED. Unlike MOVED (permanent redirect), ASK is a one-time redirect that requires sending the ASKING command to the target node before retrying the original query. The implementation: - Detects ASK responses alongside existing MOVED handling - Sends ASKING command to the target node before retrying - Reuses the MOVED redirect infrastructure (endpoint lookup, reconnection, retry logic) Also refactor parse_moved_reply() into parse_redirect_reply() that accepts the prefix as a parameter, with inline wrappers parse_moved_reply() and parse_ask_reply() for backward compatibility. Fix the hash slot calculation in redisHash(): replace the bitwise AND operator with modulo using the standard Redis cluster slot count (16384). The previous code used '& con->slots_assigned' which only produces correct results when slots_assigned is a power-of-2 minus 1. Using the spec-defined constant is always correct. Partially addresses OpenSIPS#2811
Member
|
This appears to be a partial duplicate of #3815 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for Redis ASK redirects during cluster resharding and fix the hash slot calculation.
ASK Redirect Handling
When a Redis cluster is resharding (migrating slots between nodes), the source node returns an
ASKresponse instead ofMOVED. The key difference:ASKINGto the target node before retryingWithout ASK handling, queries during resharding operations fail with unhandled error responses. This completes the cluster redirect support started in #3639.
Implementation
ASKINGcommand to the target node before retrying the original queryparse_moved_reply()intoparse_redirect_reply()that accepts the prefix as a parameter, with inline wrappersparse_moved_reply()andparse_ask_reply()for backward compatibilityHash Slot Fix
Replaces
crc16(...) & con->slots_assignedwithcrc16(...) % REDIS_CLUSTER_SLOTS(16384). The bitwise AND only produces correct modulo results when the operand is2^n - 1. Using the spec-defined constant (RFC: Redis Cluster Specification) is always correct regardless of theslots_assignedvalue.Testing
-Wall -Wextra -Werror, zero warningsPartially addresses #2811