Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ protected BaseLoadBalancer.Cluster.Action getAction(int fromServer, int fromRegi
if (fromServer < 0 || toServer < 0) {
return BaseLoadBalancer.Cluster.NullAction;
}
if (fromRegion > 0 && toRegion > 0) {
if (fromRegion >= 0 && toRegion >= 0) {
return new BaseLoadBalancer.Cluster.SwapRegionsAction(fromServer, fromRegion,
toServer, toRegion);
} else if (fromRegion > 0) {
} else if (fromRegion >= 0) {
return new BaseLoadBalancer.Cluster.MoveRegionAction(fromRegion, fromServer, toServer);
} else if (toRegion > 0) {
} else if (toRegion >= 0) {
return new BaseLoadBalancer.Cluster.MoveRegionAction(toRegion, toServer, fromServer);
} else {
return BaseLoadBalancer.Cluster.NullAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ protected void setCandidateGenerators(List<CandidateGenerator> customCandidateGe
this.candidateGenerators = customCandidateGenerators;
}

/**
* Exposed for Testing!
*/
public List<CandidateGenerator> getCandidateGenerators() {
return this.candidateGenerators;
}

@Override
protected void setSlop(Configuration conf) {
this.slop = conf.getFloat("hbase.regions.slop", 0.001F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static void beforeAllTests() throws IOException {
RULES_FILE);
BalancerTestBase.loadBalancer = new StochasticLoadBalancer();
BalancerTestBase.loadBalancer.setConf(BalancerTestBase.conf);
BalancerTestBase.loadBalancer.getCandidateGenerators().add(new FairRandomCandidateGenerator());
}

@Test
Expand Down Expand Up @@ -279,4 +280,26 @@ private ServerAndLoad createServer(final String host) {
ServerName sn = ServerName.valueOf(host, port, startCode);
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);
}
}
}