Skip to content

Commit 31d8a86

Browse files
committed
HBASE-25635 CandidateGenerator may miss some region balance actions
1 parent 830d289 commit 31d8a86

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.hadoop.hbase.client.RegionInfo;
2727

2828
import org.apache.yetus.audience.InterfaceAudience;
29-
3029
/**
3130
* Generates a candidate action to be applied to the cluster for cost function search
3231
*/
@@ -124,12 +123,12 @@ protected BaseLoadBalancer.Cluster.Action getAction(int fromServer, int fromRegi
124123
if (fromServer < 0 || toServer < 0) {
125124
return BaseLoadBalancer.Cluster.NullAction;
126125
}
127-
if (fromRegion > 0 && toRegion > 0) {
126+
if (fromRegion >= 0 && toRegion >= 0) {
128127
return new BaseLoadBalancer.Cluster.SwapRegionsAction(fromServer, fromRegion,
129128
toServer, toRegion);
130-
} else if (fromRegion > 0) {
129+
} else if (fromRegion >= 0) {
131130
return new BaseLoadBalancer.Cluster.MoveRegionAction(fromRegion, fromServer, toServer);
132-
} else if (toRegion > 0) {
131+
} else if (toRegion >= 0) {
133132
return new BaseLoadBalancer.Cluster.MoveRegionAction(toRegion, toServer, fromServer);
134133
} else {
135134
return BaseLoadBalancer.Cluster.NullAction;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ protected void setCandidateGenerators(List<CandidateGenerator> customCandidateGe
263263
this.candidateGenerators = customCandidateGenerators;
264264
}
265265

266+
public List<CandidateGenerator> getCandidateGenerators() {
267+
return this.candidateGenerators;
268+
}
269+
266270
@Override
267271
protected void setSlop(Configuration conf) {
268272
this.slop = conf.getFloat("hbase.regions.slop", 0.001F);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public static void beforeAllTests() throws IOException {
6767
BalancerTestBase.conf.setBoolean("hbase.master.balancer.stochastic.runMaxSteps", true);
6868
BalancerTestBase.conf.set(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY,
6969
HeterogeneousRegionCountCostFunction.class.getName());
70+
7071
// Need to ensure test dir has been created.
7172
assertTrue(FileSystem.get(HTU.getConfiguration()).mkdirs(HTU.getDataTestDir()));
7273
RULES_FILE = HTU.getDataTestDir(
@@ -76,6 +77,7 @@ public static void beforeAllTests() throws IOException {
7677
RULES_FILE);
7778
BalancerTestBase.loadBalancer = new StochasticLoadBalancer();
7879
BalancerTestBase.loadBalancer.setConf(BalancerTestBase.conf);
80+
BalancerTestBase.loadBalancer.getCandidateGenerators().add(new FairRandomCandidateGenerator());
7981
}
8082

8183
@Test
@@ -279,4 +281,26 @@ private ServerAndLoad createServer(final String host) {
279281
ServerName sn = ServerName.valueOf(host, port, startCode);
280282
return new ServerAndLoad(sn, 0);
281283
}
284+
285+
static class FairRandomCandidateGenerator extends
286+
StochasticLoadBalancer.RandomCandidateGenerator {
287+
288+
@Override
289+
public BaseLoadBalancer.Cluster.Action pickRandomRegions(BaseLoadBalancer.Cluster cluster,
290+
int thisServer, int otherServer) {
291+
if (thisServer < 0 || otherServer < 0) {
292+
return BaseLoadBalancer.Cluster.NullAction;
293+
}
294+
295+
int thisRegion = pickRandomRegion(cluster, thisServer, 0.5);
296+
int otherRegion = pickRandomRegion(cluster, otherServer, 0.5);
297+
298+
return getAction(thisServer, thisRegion, otherServer, otherRegion);
299+
}
300+
301+
@Override
302+
BaseLoadBalancer.Cluster.Action generate(BaseLoadBalancer.Cluster cluster) {
303+
return super.generate(cluster);
304+
}
305+
}
282306
}

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/SecureTestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
public class SecureTestUtil {
7272

7373
private static final Logger LOG = LoggerFactory.getLogger(SecureTestUtil.class);
74-
private static final int WAIT_TIME = 10000;
74+
private static final int WAIT_TIME = 30000;
7575

7676
public static void configureSuperuser(Configuration conf) throws IOException {
7777
// The secure minicluster creates separate service principals based on the

0 commit comments

Comments
 (0)