HBASE-25635 CandidateGenerator may miss some region balance actions (#3024)
Signed-off-by: Viraj Jasani <vjasani@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
876fec1648
commit
aeec8ca64b
|
@ -124,12 +124,12 @@ abstract class CandidateGenerator {
|
||||||
if (fromServer < 0 || toServer < 0) {
|
if (fromServer < 0 || toServer < 0) {
|
||||||
return BaseLoadBalancer.Cluster.NullAction;
|
return BaseLoadBalancer.Cluster.NullAction;
|
||||||
}
|
}
|
||||||
if (fromRegion > 0 && toRegion > 0) {
|
if (fromRegion >= 0 && toRegion >= 0) {
|
||||||
return new BaseLoadBalancer.Cluster.SwapRegionsAction(fromServer, fromRegion,
|
return new BaseLoadBalancer.Cluster.SwapRegionsAction(fromServer, fromRegion,
|
||||||
toServer, toRegion);
|
toServer, toRegion);
|
||||||
} else if (fromRegion > 0) {
|
} else if (fromRegion >= 0) {
|
||||||
return new BaseLoadBalancer.Cluster.MoveRegionAction(fromRegion, fromServer, toServer);
|
return new BaseLoadBalancer.Cluster.MoveRegionAction(fromRegion, fromServer, toServer);
|
||||||
} else if (toRegion > 0) {
|
} else if (toRegion >= 0) {
|
||||||
return new BaseLoadBalancer.Cluster.MoveRegionAction(toRegion, toServer, fromServer);
|
return new BaseLoadBalancer.Cluster.MoveRegionAction(toRegion, toServer, fromServer);
|
||||||
} else {
|
} else {
|
||||||
return BaseLoadBalancer.Cluster.NullAction;
|
return BaseLoadBalancer.Cluster.NullAction;
|
||||||
|
|
|
@ -263,6 +263,13 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
this.candidateGenerators = customCandidateGenerators;
|
this.candidateGenerators = customCandidateGenerators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposed for Testing!
|
||||||
|
*/
|
||||||
|
public List<CandidateGenerator> getCandidateGenerators() {
|
||||||
|
return this.candidateGenerators;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setSlop(Configuration conf) {
|
protected void setSlop(Configuration conf) {
|
||||||
this.slop = conf.getFloat("hbase.regions.slop", 0.001F);
|
this.slop = conf.getFloat("hbase.regions.slop", 0.001F);
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class TestStochasticLoadBalancerHeterogeneousCost extends BalancerTestBas
|
||||||
RULES_FILE);
|
RULES_FILE);
|
||||||
BalancerTestBase.loadBalancer = new StochasticLoadBalancer();
|
BalancerTestBase.loadBalancer = new StochasticLoadBalancer();
|
||||||
BalancerTestBase.loadBalancer.setConf(BalancerTestBase.conf);
|
BalancerTestBase.loadBalancer.setConf(BalancerTestBase.conf);
|
||||||
|
BalancerTestBase.loadBalancer.getCandidateGenerators().add(new FairRandomCandidateGenerator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -279,4 +280,26 @@ public class TestStochasticLoadBalancerHeterogeneousCost extends BalancerTestBas
|
||||||
ServerName sn = ServerName.valueOf(host, port, startCode);
|
ServerName sn = ServerName.valueOf(host, port, startCode);
|
||||||
return new ServerAndLoad(sn, 0);
|
return new ServerAndLoad(sn, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class FairRandomCandidateGenerator extends
|
||||||
|
StochasticLoadBalancer.RandomCandidateGenerator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseLoadBalancer.Cluster.Action pickRandomRegions(BaseLoadBalancer.Cluster cluster,
|
||||||
|
int thisServer, int otherServer) {
|
||||||
|
if (thisServer < 0 || otherServer < 0) {
|
||||||
|
return BaseLoadBalancer.Cluster.NullAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
int thisRegion = pickRandomRegion(cluster, thisServer, 0.5);
|
||||||
|
int otherRegion = pickRandomRegion(cluster, otherServer, 0.5);
|
||||||
|
|
||||||
|
return getAction(thisServer, thisRegion, otherServer, otherRegion);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
BaseLoadBalancer.Cluster.Action generate(BaseLoadBalancer.Cluster cluster) {
|
||||||
|
return super.generate(cluster);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue