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 committed by GitHub
parent 8ae4d65aa5
commit 85d8ec7dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View File

@ -73,13 +73,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
protected static final int MIN_SERVER_BALANCE = 2; protected static final int MIN_SERVER_BALANCE = 2;
private volatile boolean stopped = false; private volatile boolean stopped = false;
protected RegionHDFSBlockLocationFinder regionFinder; protected volatile RegionHDFSBlockLocationFinder 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;
@ -386,14 +386,21 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
return 0.2f; return 0.2f;
} }
private RegionHDFSBlockLocationFinder createRegionLocationFinder(Configuration conf) {
RegionHDFSBlockLocationFinder finder = new RegionHDFSBlockLocationFinder();
finder.setConf(conf);
finder.setClusterInfoProvider(provider);
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()));
this.rackManager = new RackManager(conf); this.rackManager = new RackManager(conf);
useRegionFinder = conf.getBoolean("hbase.master.balancer.uselocality", true); useRegionFinder = conf.getBoolean("hbase.master.balancer.uselocality", true);
if (useRegionFinder) { if (useRegionFinder) {
regionFinder = new RegionHDFSBlockLocationFinder(); regionFinder = createRegionLocationFinder(conf);
regionFinder.setConf(conf); } else {
regionFinder.setClusterInfoProvider(provider); regionFinder = null;
} }
this.isByTable = conf.getBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable); this.isByTable = conf.getBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable);
// Print out base configs. Don't print overallSlop since it for simple balancer exclusively. // Print out base configs. Don't print overallSlop since it for simple balancer exclusively.