Skip to content

Commit 702220a

Browse files
committed
HBASE-25759 The master services field in LocalityBasedCostFunction is never used (#3144)
Signed-off-by: Yulin Niu <niuyulin@apache.org>
1 parent b071902 commit 702220a

File tree

3 files changed

+16
-48
lines changed

3 files changed

+16
-48
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.apache.hadoop.hbase.master.RackManager;
5656
import org.apache.hadoop.hbase.master.RegionPlan;
5757
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.Action.Type;
58-
import org.apache.hadoop.hbase.namequeues.NamedQueueRecorder;
5958
import org.apache.hadoop.hbase.net.Address;
6059
import org.apache.yetus.audience.InterfaceAudience;
6160
import org.slf4j.Logger;
@@ -92,11 +91,6 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
9291
protected boolean useRegionFinder;
9392
protected boolean isByTable = false;
9493

95-
/**
96-
* Use to add balancer decision history to ring-buffer
97-
*/
98-
protected NamedQueueRecorder namedQueueRecorder;
99-
10094
private static class DefaultRackManager extends RackManager {
10195
@Override
10296
public String getRack(ServerName server) {

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

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
158158
private RegionReplicaHostCostFunction regionReplicaHostCostFunction;
159159
private RegionReplicaRackCostFunction regionReplicaRackCostFunction;
160160

161+
/**
162+
* Use to add balancer decision history to ring-buffer
163+
*/
164+
NamedQueueRecorder namedQueueRecorder;
165+
161166
/**
162167
* The constructor that pass a MetricsStochasticBalancer to BaseLoadBalancer to replace its
163168
* default MetricsBalancer
@@ -184,8 +189,8 @@ public synchronized void setConf(Configuration conf) {
184189
if (localityCandidateGenerator == null) {
185190
localityCandidateGenerator = new LocalityBasedCandidateGenerator(services);
186191
}
187-
localityCost = new ServerLocalityCostFunction(conf, services);
188-
rackLocalityCost = new RackLocalityCostFunction(conf, services);
192+
localityCost = new ServerLocalityCostFunction(conf);
193+
rackLocalityCost = new RackLocalityCostFunction(conf);
189194

190195
if (this.candidateGenerators == null) {
191196
candidateGenerators = Lists.newArrayList();
@@ -305,8 +310,6 @@ public void updateMetricsSize(int size) {
305310
@Override
306311
public synchronized void setMasterServices(MasterServices masterServices) {
307312
super.setMasterServices(masterServices);
308-
this.localityCost.setServices(masterServices);
309-
this.rackLocalityCost.setServices(masterServices);
310313
this.localityCandidateGenerator.setServices(masterServices);
311314
}
312315

@@ -1057,17 +1060,11 @@ static abstract class LocalityBasedCostFunction extends CostFunction {
10571060
private double bestLocality; // best case locality across cluster weighted by local data size
10581061
private double locality; // current locality across cluster weighted by local data size
10591062

1060-
private MasterServices services;
1061-
1062-
LocalityBasedCostFunction(Configuration conf,
1063-
MasterServices srv,
1064-
LocalityType type,
1065-
String localityCostKey,
1066-
float defaultLocalityCost) {
1063+
LocalityBasedCostFunction(Configuration conf, LocalityType type, String localityCostKey,
1064+
float defaultLocalityCost) {
10671065
super(conf);
10681066
this.type = type;
10691067
this.setMultiplier(conf.getFloat(localityCostKey, defaultLocalityCost));
1070-
this.services = srv;
10711068
this.locality = 0.0;
10721069
this.bestLocality = 0.0;
10731070
}
@@ -1077,21 +1074,12 @@ static abstract class LocalityBasedCostFunction extends CostFunction {
10771074
*/
10781075
abstract int regionIndexToEntityIndex(int region);
10791076

1080-
public void setServices(MasterServices srvc) {
1081-
this.services = srvc;
1082-
}
1083-
10841077
@Override
10851078
void init(Cluster cluster) {
10861079
super.init(cluster);
10871080
locality = 0.0;
10881081
bestLocality = 0.0;
10891082

1090-
// If no master, no computation will work, so assume 0 cost
1091-
if (this.services == null) {
1092-
return;
1093-
}
1094-
10951083
for (int region = 0; region < cluster.numRegions; region++) {
10961084
locality += getWeightedLocality(region, regionIndexToEntityIndex(region));
10971085
bestLocality += getWeightedLocality(region, getMostLocalEntityForRegion(region));
@@ -1107,9 +1095,6 @@ void init(Cluster cluster) {
11071095
protected void regionMoved(int region, int oldServer, int newServer) {
11081096
int oldEntity = type == LocalityType.SERVER ? oldServer : cluster.serverIndexToRackIndex[oldServer];
11091097
int newEntity = type == LocalityType.SERVER ? newServer : cluster.serverIndexToRackIndex[newServer];
1110-
if (this.services == null) {
1111-
return;
1112-
}
11131098
double localityDelta = getWeightedLocality(region, newEntity) - getWeightedLocality(region, oldEntity);
11141099
double normalizedDelta = bestLocality == 0 ? 0.0 : localityDelta / bestLocality;
11151100
locality += normalizedDelta;
@@ -1135,14 +1120,8 @@ static class ServerLocalityCostFunction extends LocalityBasedCostFunction {
11351120
private static final String LOCALITY_COST_KEY = "hbase.master.balancer.stochastic.localityCost";
11361121
private static final float DEFAULT_LOCALITY_COST = 25;
11371122

1138-
ServerLocalityCostFunction(Configuration conf, MasterServices srv) {
1139-
super(
1140-
conf,
1141-
srv,
1142-
LocalityType.SERVER,
1143-
LOCALITY_COST_KEY,
1144-
DEFAULT_LOCALITY_COST
1145-
);
1123+
ServerLocalityCostFunction(Configuration conf) {
1124+
super(conf, LocalityType.SERVER, LOCALITY_COST_KEY, DEFAULT_LOCALITY_COST);
11461125
}
11471126

11481127
@Override
@@ -1156,14 +1135,8 @@ static class RackLocalityCostFunction extends LocalityBasedCostFunction {
11561135
private static final String RACK_LOCALITY_COST_KEY = "hbase.master.balancer.stochastic.rackLocalityCost";
11571136
private static final float DEFAULT_RACK_LOCALITY_COST = 15;
11581137

1159-
public RackLocalityCostFunction(Configuration conf, MasterServices services) {
1160-
super(
1161-
conf,
1162-
services,
1163-
LocalityType.RACK,
1164-
RACK_LOCALITY_COST_KEY,
1165-
DEFAULT_RACK_LOCALITY_COST
1166-
);
1138+
public RackLocalityCostFunction(Configuration conf) {
1139+
super(conf, LocalityType.RACK, RACK_LOCALITY_COST_KEY, DEFAULT_RACK_LOCALITY_COST);
11671140
}
11681141

11691142
@Override

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@
5050
import org.apache.hadoop.hbase.testclassification.MediumTests;
5151
import org.apache.hadoop.hbase.util.Bytes;
5252
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
53-
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
5453
import org.junit.ClassRule;
5554
import org.junit.Test;
5655
import org.junit.experimental.categories.Category;
5756

57+
import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;
58+
5859
@Category({ MasterTests.class, MediumTests.class })
5960
public class TestStochasticLoadBalancer extends BalancerTestBase {
6061

@@ -195,7 +196,7 @@ public void testLocalityCost() throws Exception {
195196
Configuration conf = HBaseConfiguration.create();
196197
MockNoopMasterServices master = new MockNoopMasterServices();
197198
StochasticLoadBalancer.CostFunction
198-
costFunction = new ServerLocalityCostFunction(conf, master);
199+
costFunction = new ServerLocalityCostFunction(conf);
199200

200201
for (int test = 0; test < clusterRegionLocationMocks.length; test++) {
201202
int[][] clusterRegionLocations = clusterRegionLocationMocks[test];

0 commit comments

Comments
 (0)