AZAffinity & AZAffinityReplicasAndPrimary Implementation #47
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.
Fixes: #23
Implements support for AZAffinity and AZAffinityReplicasAndPrimary read strategies based on the Valkey blog post on AZ Affinity.
Developers can now use:
scaleReads: "AZAffinity" | "AZAffinityReplicasAndPrimary", clientAz: "zone-a" // etc.
During Redis initialization, a HELLO 3 call is made to retrieve the availabilityZone, which is then saved under each node instance.
A new selectNodeAz method was introduced. This method is called internally when scaleReads is set to AZAffinity or AZAffinityReplicasAndPrimary. Based on the strategy, it routes commands to the most suitable node:
AZAffinity logic:
AZAffinityReplicasAndPrimary logic:
Tests
Tests were added to cover each of the above scenarios.
However, two tests sometimes pass and sometimes fail:
I couldn't figure out exactly why this happens. I couldn’t find a solution
AZAffinity → selects remote replica when no local replica exists
AZAffinityReplicasAndPrimary → selects local primary when no local replica exists
and I’m unsure if I’ve placed the test logic in the best place,
or if additional handling is needed in selectNodeAz or elsewhere