You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2021/11/01 16:20:22 UTC

[GitHub] [hbase] clarax commented on a change in pull request #3723: HBASE-26309 Balancer tends to move regions to the server at the end o…

clarax commented on a change in pull request #3723:
URL: https://github.com/apache/hbase/pull/3723#discussion_r740344466



##########
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:
       @Apache9 Thank you for checking the code and reference. Yes, this is a in place random selection for stream data. Updating the comments. 




-- 
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: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org