Repository navigation
Order clusters by size when picking hosts for agent load balancing - #14737
Open
MuhammetSoil wants to merge 1 commit into
Open
MuhammetSoil wants to merge 1 commit into
MuhammetSoil wants to merge 1 commit into
Conversation
The comparator used by ClusterBasedAgentLoadBalancerPlanner.sortByClusterSize never returned a negative value and returned 0 when the first cluster was larger, so it broke the Comparator contract and left the clusters mostly in HashMap order. It also threw a NullPointerException when only the second cluster had no host list. Order the clusters by host count, largest first, with clusters without a host list last, as getHostsToRebalance expects. Add unit tests. Fixes apache#14625
|
Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
|
This branch has not been deployed
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
This PR fixes the cluster ordering used by agent load balancing (#14625).
ClusterBasedAgentLoadBalancerPlanner.getHostsToRebalance()groups the Up routing hosts of amanagement server by cluster and then walks the clusters in the order returned by
sortByClusterSize(), taking whole clusters until it has given away enough hosts. That walkassumes the clusters come largest first.
The comparator in
sortByClusterSize()does not implement that order:1when the first cluster is smaller, but0(equal) when it is larger, so itnever says that one cluster comes before another;
compare(a, b)andcompare(b, a)can both be0or one of them1),which breaks the
Comparatorcontract;NullPointerExceptionif only the second cluster has no host list.As a result,
Collections.sort()mostly keeps theHashMapiteration order (cluster id order),and which clusters a management server hands over during rebalancing depends on that order rather
than on cluster size. For example, clusters with 1, 3 and 2 hosts (ids 1, 2, 3) come back as
[1, 2, 3]instead of[2, 3, 1].The comparator is replaced with one that orders by host count, largest first, with clusters
without a host list last.
sortis stable, so clusters of the same size keep their previousrelative order. Nothing else in the planner changes.
Unit tests are added for the ordering, the null handling and that all entries are kept. The first
test fails without the fix.
The code is the same on
4.20,4.22andmain; this targets4.22so it can be merged forward.Fixes: #14625
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
ClusterBasedAgentLoadBalancerPlannerTest; ran it withmvn -pl engine/orchestration test -Dtest=ClusterBasedAgentLoadBalancerPlannerTeston JDK 11.sortByClusterSizePutsLargestClusterFirstfails against the previous comparator(it returns
[1, 2, 3]) and passes with this change.How did you try to break this feature and the system with this change?
Tested with ten clusters in random size order, and a cluster
mapped to a
nullhost list (which made the previous comparator throw when it was the secondargument).