clarax commented on a change in pull request #3723:
URL: https://github.com/apache/hbase/pull/3723#discussion_r736884334
##########
File path:
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadCandidateGenerator.java
##########
@@ -34,27 +35,51 @@ BalanceAction generate(BalancerClusterState cluster) {
private int pickLeastLoadedServer(final BalancerClusterState cluster, int
thisServer) {
Integer[] servers = cluster.serverIndicesSortedByRegionCount;
- int index = 0;
- while (servers[index] == null || servers[index] == thisServer) {
- index++;
- if (index == servers.length) {
- return -1;
+ int selectedIndex = -1;
+ double currentLargestRandom = -1;
+ for (int i = 0; i < servers.length; i++) {
+ if (servers[i] == null || servers[i] == thisServer) {
+ continue;
+ }
+ if (selectedIndex != -1
+ && cluster.getNumRegionsComparator().compare(servers[i],
servers[selectedIndex]) != 0) {
+ // Exhausted servers of the same region count
+ break;
+ }
+ // we don't know how many servers have the same region count, we will
randomly select one
Review comment:
Oh yes, it used an Integer[] The reason was to hold null value. I am
actually tempted to change it to ArrayList<Integer> so we don't have to deal
with null value in a fixed size array. The reason not to use the utility class
is not to construct a new array for every iteration. The existing code sorts
the data in place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]