ranganathg commented on code in PR #4258:
URL: https://github.com/apache/hbase/pull/4258#discussion_r1757034690


##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java:
##########
@@ -276,14 +323,68 @@ public void updateClusterMetrics(ClusterMetrics st) {
     try {
       // by-table or ensemble mode
       int tablesCount = isByTable ? provider.getNumberOfTables() : 1;
-      int functionsCount = getCostFunctionNames().length;
+      int functionsCount = getCostFunctionNames(false).length;
 
       updateMetricsSize(tablesCount * (functionsCount + 1)); // +1 for overall
     } catch (Exception e) {
       LOG.error("failed to get the size of all tables", e);
     }
   }
 
+  @Override
+  public List<RegionPlan>
+    balanceCluster(Map<TableName, Map<ServerName, List<RegionInfo>>> 
loadOfAllTable) {
+    long current = EnvironmentEdgeManager.currentTime();
+    if (
+      clusterStatusCheckers != null && current - lastCoarseTimestamp > 
getConf().getLong(
+        CLUSTER_COARSE_BALANCE_MIN_INTERVAL_KEY, 
CLUSTER_COARSE_BALANCE_MIN_INTERVAL_DEFAULT)
+    ) {
+      for (ClusterStatusBalanceChecker clusterStatusBalancer : 
clusterStatusCheckers) {
+        boolean coarseBalance = 
clusterStatusBalancer.needsCoarseBalance(loadOfAllTable);
+        if (coarseBalance) {
+          // no matter whether the coarse balance generates plans, we record 
the
+          // lastCoarseTimestamp as the timestamp of calculating coarse plans
+          lastCoarseTimestamp = current;
+          List<RegionPlan> plans = coarseBalanceCluster(loadOfAllTable);
+          if (plans != null && !plans.isEmpty()) {
+            LOG.debug("Cluster needs coarse balance, and plans size={}", 
plans.size());
+            return plans;
+          } else {
+            LOG.warn("Cluster needs coarse balance, but generated no plans by 
current "
+              + "coarseCostFunctions, please see more details in HBASE-25768");
+            break;
+          }
+        }
+      }
+    }
+    return super.balanceCluster(loadOfAllTable);
+  }
+
+  /**
+   * Use the coarse cost functions to balance cluster.
+   */
+  @RestrictedApi(explanation = "Should only be called in tests", link = "",
+      allowedOnPath = ".*(/src/test/.*|StochasticLoadBalancer).java")
+  List<RegionPlan>
+    coarseBalanceCluster(Map<TableName, Map<ServerName, List<RegionInfo>>> 
loadOfAllTable) {
+    preBalanceCluster(loadOfAllTable);
+    if (isByTable) {

Review Comment:
   when we found that the cluster needs coarse balancing, does it make sense to 
balance by Table? when ever we find that cluster needs coarse balancing, should 
we only do at the cluster level?



-- 
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]

Reply via email to