Skip to content

Commit 7cec975

Browse files
bharathvapurtell
authored andcommitted
HBASE-23116 LoadBalancer should log table name when balancing per table (#689)
This commit adds table name to the logging context when StochasticLoadBalancer is configured "per table". Signed-off-by: Andrew Purtell <[email protected]>
1 parent 6738c2b commit 7cec975

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,11 @@ protected boolean needsBalance(Cluster cluster) {
305305

306306
if (total <= 0 || sumMultiplier <= 0
307307
|| (sumMultiplier > 0 && (total / sumMultiplier) < minCostNeedBalance)) {
308-
LOG.info("Skipping load balancing because balanced cluster; " + "total cost is " + total
309-
+ ", sum multiplier is " + sumMultiplier + " min cost which need balance is "
310-
+ minCostNeedBalance);
308+
final String loadBalanceTarget =
309+
isByTable ? String.format("table (%s)", tableName) : "cluster";
310+
LOG.info(String.format("Skipping load balancing because the %s is balanced. Total cost: %s, "
311+
+ "Sum multiplier: %s, Minimum cost needed for balance: %s", loadBalanceTarget, total,
312+
sumMultiplier, minCostNeedBalance));
311313
return false;
312314
}
313315
return true;

hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,18 @@ public void testKeepRegionLoad() throws Exception {
160160
public void testNeedBalance() {
161161
float minCost = conf.getFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.05f);
162162
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 1.0f);
163-
loadBalancer.setConf(conf);
164-
for (int[] mockCluster : clusterStateMocks) {
165-
Map<ServerName, List<HRegionInfo>> servers = mockClusterServers(mockCluster);
166-
List<RegionPlan> plans = loadBalancer.balanceCluster(servers);
167-
assertNull(plans);
163+
try {
164+
loadBalancer.setConf(conf);
165+
for (int[] mockCluster : clusterStateMocks) {
166+
Map<ServerName, List<HRegionInfo>> servers = mockClusterServers(mockCluster);
167+
List<RegionPlan> plans = loadBalancer.balanceCluster(servers);
168+
assertNull(plans);
169+
}
170+
} finally {
171+
// reset config
172+
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", minCost);
173+
loadBalancer.setConf(conf);
168174
}
169-
// reset config
170-
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", minCost);
171-
loadBalancer.setConf(conf);
172175
}
173176

174177
/**

0 commit comments

Comments
 (0)