HBASE-25883 The regionFinder and rackManager fields in BaseLoadBalancer should be volatile (#3262)

Signed-off-by: meiyi <myimeiyi@gmail.com>
This commit is contained in:
Duo Zhang 2021-05-15 20:20:03 +08:00
parent 1bb16fea5b
commit d5d972f92e

View File

@ -80,13 +80,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
private static final Predicate<ServerMetrics> IDLE_SERVER_PREDICATOR private static final Predicate<ServerMetrics> IDLE_SERVER_PREDICATOR
= load -> load.getRegionMetrics().isEmpty(); = load -> load.getRegionMetrics().isEmpty();
protected RegionLocationFinder regionFinder; protected volatile RegionLocationFinder regionFinder;
protected boolean useRegionFinder; protected boolean useRegionFinder;
protected boolean isByTable = false; protected boolean isByTable = false;
// slop for regions // slop for regions
protected float slop; protected float slop;
protected RackManager rackManager; protected volatile RackManager rackManager;
protected MetricsBalancer metricsBalancer = null; protected MetricsBalancer metricsBalancer = null;
protected ClusterMetrics clusterStatus = null; protected ClusterMetrics clusterStatus = null;
protected ServerName masterServerName; protected ServerName masterServerName;
@ -546,6 +546,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
return 0.2f; return 0.2f;
} }
private RegionLocationFinder createRegionLocationFinder(Configuration conf) {
RegionLocationFinder finder = new RegionLocationFinder();
finder.setConf(conf);
finder.setServices(services);
return finder;
}
protected void loadConf(Configuration conf) { protected void loadConf(Configuration conf) {
this.slop =normalizeSlop(conf.getFloat("hbase.regions.slop", getDefaultSlop())); this.slop =normalizeSlop(conf.getFloat("hbase.regions.slop", getDefaultSlop()));
@ -554,9 +561,11 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
this.rackManager = new RackManager(getConf()); this.rackManager = new RackManager(getConf());
useRegionFinder = conf.getBoolean("hbase.master.balancer.uselocality", true); useRegionFinder = conf.getBoolean("hbase.master.balancer.uselocality", true);
if (useRegionFinder) { if (useRegionFinder) {
regionFinder = new RegionLocationFinder(); regionFinder = createRegionLocationFinder(conf);
regionFinder.setConf(conf); } else {
regionFinder = null;
} }
this.isByTable = conf.getBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable); this.isByTable = conf.getBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable);
LOG.info("slop={}, systemTablesOnMaster={}", this.slop, this.onlySystemTablesOnMaster); LOG.info("slop={}, systemTablesOnMaster={}", this.slop, this.onlySystemTablesOnMaster);
} }