@@ -158,6 +158,11 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
158
158
private RegionReplicaHostCostFunction regionReplicaHostCostFunction ;
159
159
private RegionReplicaRackCostFunction regionReplicaRackCostFunction ;
160
160
161
+ /**
162
+ * Use to add balancer decision history to ring-buffer
163
+ */
164
+ NamedQueueRecorder namedQueueRecorder ;
165
+
161
166
/**
162
167
* The constructor that pass a MetricsStochasticBalancer to BaseLoadBalancer to replace its
163
168
* default MetricsBalancer
@@ -184,8 +189,8 @@ public synchronized void setConf(Configuration conf) {
184
189
if (localityCandidateGenerator == null ) {
185
190
localityCandidateGenerator = new LocalityBasedCandidateGenerator (services );
186
191
}
187
- localityCost = new ServerLocalityCostFunction (conf , services );
188
- rackLocalityCost = new RackLocalityCostFunction (conf , services );
192
+ localityCost = new ServerLocalityCostFunction (conf );
193
+ rackLocalityCost = new RackLocalityCostFunction (conf );
189
194
190
195
if (this .candidateGenerators == null ) {
191
196
candidateGenerators = Lists .newArrayList ();
@@ -305,8 +310,6 @@ public void updateMetricsSize(int size) {
305
310
@ Override
306
311
public synchronized void setMasterServices (MasterServices masterServices ) {
307
312
super .setMasterServices (masterServices );
308
- this .localityCost .setServices (masterServices );
309
- this .rackLocalityCost .setServices (masterServices );
310
313
this .localityCandidateGenerator .setServices (masterServices );
311
314
}
312
315
@@ -1057,17 +1060,11 @@ static abstract class LocalityBasedCostFunction extends CostFunction {
1057
1060
private double bestLocality ; // best case locality across cluster weighted by local data size
1058
1061
private double locality ; // current locality across cluster weighted by local data size
1059
1062
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 ) {
1067
1065
super (conf );
1068
1066
this .type = type ;
1069
1067
this .setMultiplier (conf .getFloat (localityCostKey , defaultLocalityCost ));
1070
- this .services = srv ;
1071
1068
this .locality = 0.0 ;
1072
1069
this .bestLocality = 0.0 ;
1073
1070
}
@@ -1077,21 +1074,12 @@ static abstract class LocalityBasedCostFunction extends CostFunction {
1077
1074
*/
1078
1075
abstract int regionIndexToEntityIndex (int region );
1079
1076
1080
- public void setServices (MasterServices srvc ) {
1081
- this .services = srvc ;
1082
- }
1083
-
1084
1077
@ Override
1085
1078
void init (Cluster cluster ) {
1086
1079
super .init (cluster );
1087
1080
locality = 0.0 ;
1088
1081
bestLocality = 0.0 ;
1089
1082
1090
- // If no master, no computation will work, so assume 0 cost
1091
- if (this .services == null ) {
1092
- return ;
1093
- }
1094
-
1095
1083
for (int region = 0 ; region < cluster .numRegions ; region ++) {
1096
1084
locality += getWeightedLocality (region , regionIndexToEntityIndex (region ));
1097
1085
bestLocality += getWeightedLocality (region , getMostLocalEntityForRegion (region ));
@@ -1107,9 +1095,6 @@ void init(Cluster cluster) {
1107
1095
protected void regionMoved (int region , int oldServer , int newServer ) {
1108
1096
int oldEntity = type == LocalityType .SERVER ? oldServer : cluster .serverIndexToRackIndex [oldServer ];
1109
1097
int newEntity = type == LocalityType .SERVER ? newServer : cluster .serverIndexToRackIndex [newServer ];
1110
- if (this .services == null ) {
1111
- return ;
1112
- }
1113
1098
double localityDelta = getWeightedLocality (region , newEntity ) - getWeightedLocality (region , oldEntity );
1114
1099
double normalizedDelta = bestLocality == 0 ? 0.0 : localityDelta / bestLocality ;
1115
1100
locality += normalizedDelta ;
@@ -1135,14 +1120,8 @@ static class ServerLocalityCostFunction extends LocalityBasedCostFunction {
1135
1120
private static final String LOCALITY_COST_KEY = "hbase.master.balancer.stochastic.localityCost" ;
1136
1121
private static final float DEFAULT_LOCALITY_COST = 25 ;
1137
1122
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 );
1146
1125
}
1147
1126
1148
1127
@ Override
@@ -1156,14 +1135,8 @@ static class RackLocalityCostFunction extends LocalityBasedCostFunction {
1156
1135
private static final String RACK_LOCALITY_COST_KEY = "hbase.master.balancer.stochastic.rackLocalityCost" ;
1157
1136
private static final float DEFAULT_RACK_LOCALITY_COST = 15 ;
1158
1137
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 );
1167
1140
}
1168
1141
1169
1142
@ Override
0 commit comments