policies: fix dc aware and rack aware policies initialization#578
Merged
dkropachev merged 1 commit intoNov 4, 2025
Merged
Conversation
In cases when nodes are listed not in a proper groups of dc (for DCAwareRoundRobinPolicy) and dc+rack (for RackAwareRoundRobinPolicy). Policy register only nodes from the last group or dc+rack. So, policy knows only last group of nodes, rest of the nodes considered to be non-existent, until node is restarted, which can be days.
Lorak-mmk
approved these changes
Nov 4, 2025
Comment on lines
255
to
257
| for dc, dc_hosts in groupby(hosts, lambda h: self._dc(h)): | ||
| self._dc_live_hosts[dc] = tuple(set(dc_hosts)) | ||
| self._dc_live_hosts[dc] = tuple({*dc_hosts, *self._dc_live_hosts.get(dc, [])}) | ||
|
|
There was a problem hiding this comment.
Personally I think such comprehensions / unpacking (or w/e is this called) is much less readable than something simpler like
for dc, dc_hosts in groupby(hosts, lambda h: self._dc(h)):
self._dc_live_hosts.setdefault(dc, set())
self._dc_live_hosts[dc].update(dc_hosts)I'd prefer it to be changed, but I won't hold this PR over that.
There was a problem hiding this comment.
Btw if we are staying with the current version, let's change .get(dc, []) to .get(dc,set()).
It won't change how the code works but makes it imo easier to reason about - _dc_live_hosts is a dict str -> set of hosts, so let's keep it that way.
sylwiaszunejko
approved these changes
Nov 4, 2025
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.
In cases when nodes are listed not in a proper groups of dc (for DCAwareRoundRobinPolicy) and dc+rack (for RackAwareRoundRobinPolicy).
Policy register only nodes from the last group or dc+rack. So, policy knows only last group of nodes, rest of the nodes considered to be non-existent, until node is restarted, which can be days.
Fixes: #576
Pre-review checklist
I have provided docstrings for the public items that I want to introduce.I have adjusted the documentation in./docs/source/.Fixes:annotations to PR description.