2323import java .util .List ;
2424import java .util .Map ;
2525
26+ import org .apache .hadoop .hbase .BaseConfigurable ;
2627import org .apache .hadoop .hbase .client .RegionInfo ;
2728
2829import org .apache .yetus .audience .InterfaceAudience ;
30+ import static org .apache .hadoop .hbase .HConstants .HBASE_MASTER_BALANCER_RANDOM_PICK_REGIONS_WITH_CONSIDER_COUNT_BALANCE ;
2931
3032/**
3133 * Generates a candidate action to be applied to the cluster for cost function search
3234 */
3335@ InterfaceAudience .Private
34- abstract class CandidateGenerator {
36+ abstract class CandidateGenerator extends BaseConfigurable {
3537
3638 abstract BaseLoadBalancer .Cluster .Action generate (BaseLoadBalancer .Cluster cluster );
3739
@@ -104,14 +106,19 @@ BaseLoadBalancer.Cluster.Action pickRandomRegions(BaseLoadBalancer.Cluster clust
104106 if (thisServer < 0 || otherServer < 0 ) {
105107 return BaseLoadBalancer .Cluster .NullAction ;
106108 }
107-
108- // Decide who is most likely to need another region
109- int thisRegionCount = cluster .getNumRegions (thisServer );
110- int otherRegionCount = cluster .getNumRegions (otherServer );
111-
112- // Assign the chance based upon the above
113- double thisChance = (thisRegionCount > otherRegionCount ) ? 0 : 0.5 ;
114- double otherChance = (thisRegionCount <= otherRegionCount ) ? 0 : 0.5 ;
109+ double thisChance = 0.5 ;
110+ double otherChance = 0.5 ;
111+ if (getConf () == null || getConf ().getBoolean (
112+ HBASE_MASTER_BALANCER_RANDOM_PICK_REGIONS_WITH_CONSIDER_COUNT_BALANCE , true )) {
113+
114+ // Decide who is most likely to need another region
115+ int thisRegionCount = cluster .getNumRegions (thisServer );
116+ int otherRegionCount = cluster .getNumRegions (otherServer );
117+
118+ // Assign the chance based upon the above
119+ thisChance = (thisRegionCount > otherRegionCount ) ? 0 : 0.5 ;
120+ otherChance = (thisRegionCount <= otherRegionCount ) ? 0 : 0.5 ;
121+ }
115122
116123 int thisRegion = pickRandomRegion (cluster , thisServer , thisChance );
117124 int otherRegion = pickRandomRegion (cluster , otherServer , otherChance );
@@ -124,12 +131,12 @@ protected BaseLoadBalancer.Cluster.Action getAction(int fromServer, int fromRegi
124131 if (fromServer < 0 || toServer < 0 ) {
125132 return BaseLoadBalancer .Cluster .NullAction ;
126133 }
127- if (fromRegion > 0 && toRegion > 0 ) {
134+ if (fromRegion >= 0 && toRegion >= 0 && fromRegion != toRegion ) {
128135 return new BaseLoadBalancer .Cluster .SwapRegionsAction (fromServer , fromRegion ,
129136 toServer , toRegion );
130- } else if (fromRegion > 0 ) {
137+ } else if (fromRegion >= 0 ) {
131138 return new BaseLoadBalancer .Cluster .MoveRegionAction (fromRegion , fromServer , toServer );
132- } else if (toRegion > 0 ) {
139+ } else if (toRegion >= 0 ) {
133140 return new BaseLoadBalancer .Cluster .MoveRegionAction (toRegion , toServer , fromServer );
134141 } else {
135142 return BaseLoadBalancer .Cluster .NullAction ;
0 commit comments