HBASE-24139 : Balancer should avoid leaving idle region servers (#1511)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
Signed-off-by: Sean Busbey <busbey@apache.org>
Signed-off-by: Anoop Sam John <anoopsamjohn@apache.org>
This commit is contained in:
Beata Sudi 2020-04-22 06:21:53 +02:00 committed by GitHub
parent af17b3ccd6
commit 5f45c8293d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -1192,6 +1192,10 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
return false; return false;
} }
if(areSomeRegionReplicasColocated(c)) return true; if(areSomeRegionReplicasColocated(c)) return true;
if(idleRegionServerExist(c)) {
return true;
}
// Check if we even need to do any load balancing // Check if we even need to do any load balancing
// HBASE-3681 check sloppiness first // HBASE-3681 check sloppiness first
float average = cs.getLoadAverage(); // for logging float average = cs.getLoadAverage(); // for logging
@ -1223,6 +1227,20 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
return false; return false;
} }
protected final boolean idleRegionServerExist(Cluster c){
boolean isServerExistsWithMoreRegions = false;
boolean isServerExistsWithZeroRegions = false;
for (int[] serverList: c.regionsPerServer){
if (serverList.length > 1) {
isServerExistsWithMoreRegions = true;
}
if (serverList.length == 0) {
isServerExistsWithZeroRegions = true;
}
}
return isServerExistsWithMoreRegions && isServerExistsWithZeroRegions;
}
/** /**
* Generates a bulk assignment plan to be used on cluster startup using a * Generates a bulk assignment plan to be used on cluster startup using a
* simple round-robin assignment. * simple round-robin assignment.

View File

@ -324,6 +324,10 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
return true; return true;
} }
if (idleRegionServerExist(cluster)){
return true;
}
double total = 0.0; double total = 0.0;
float sumMultiplier = 0.0f; float sumMultiplier = 0.0f;
for (CostFunction c : costFunctions) { for (CostFunction c : costFunctions) {

View File

@ -255,7 +255,8 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable = Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
(Map) mockClusterServersWithTables(servers); (Map) mockClusterServersWithTables(servers);
List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable); List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
assertTrue(plans == null || plans.isEmpty()); boolean emptyPlans = plans == null || plans.isEmpty();
assertTrue(emptyPlans || needsBalanceIdleRegion(mockCluster));
} }
} }
} finally { } finally {
@ -483,6 +484,10 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
contains(DummyCostFunction.class.getSimpleName())); contains(DummyCostFunction.class.getSimpleName()));
} }
private boolean needsBalanceIdleRegion(int[] cluster){
return (Arrays.stream(cluster).anyMatch(x -> x>1)) && (Arrays.stream(cluster).anyMatch(x -> x<1));
}
// This mock allows us to test the LocalityCostFunction // This mock allows us to test the LocalityCostFunction
private class MockCluster extends BaseLoadBalancer.Cluster { private class MockCluster extends BaseLoadBalancer.Cluster {