add random load balancing strategy which allows for use of the primary#4027
Merged
Conversation
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
petyaslavova
requested changes
Apr 8, 2026
petyaslavova
left a comment
Collaborator
There was a problem hiding this comment.
Hi @Pack-Yak1, thank you for your contributions! Can you please add some tests covering the changes?
Contributor
Author
|
Added test cases and responded to comments above |
petyaslavova
added a commit
that referenced
this pull request
Apr 16, 2026
#4027) * add random load balancing strategy which allows for use of the primary * address style comments * add test cases for new strategy * apply lint fixes --------- Co-authored-by: petyaslavova <[email protected]>
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.
Description of change
This MR adds a new
LoadBalancingStrategyvalue:RANDOM. It is identical to the existingRANDOM_REPLICAexcept it allows for the use of the primary as well.Our team would like to make use of the random load balancer but don't want to waste the primary, which is the motivation for this PR
Pull Request check-list
Please make sure to review and check all of these items:
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Note
Medium Risk
Changes cluster node selection for read commands by introducing a new random strategy that can route reads to primaries as well as replicas; incorrect selection boundaries could shift traffic patterns or expose edge cases in slot node lists.
Overview
Adds a new
LoadBalancingStrategy.RANDOMoption that randomly selects from all nodes serving a slot (including the primary), alongside the existing replica-only random behavior.Refactors the load balancer’s random selection into
_get_random_server_index(list_size, replicas_only)and updates sync/async cluster tests to cover the new strategy with deterministicrandom.randintmocking and adjusted expectations.Reviewed by Cursor Bugbot for commit 45e96dd. Bugbot is set up for automated code reviews on this repo. Configure here.