Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-24418 Consolidate Normalizer implementations #1786

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions hbase-common/src/main/resources/hbase-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -604,30 +604,54 @@ possible configurations would overwhelm and obscure the important.
<property>
<name>hbase.balancer.period</name>
<value>300000</value>
<description>Period at which the region balancer runs in the Master.</description>
<description>Period at which the region balancer runs in the Master, in
milliseconds.</description>
</property>
<property>
<name>hbase.regions.slop</name>
<value>0.001</value>
<description>Rebalance if any regionserver has average + (average * slop) regions.
The default value of this parameter is 0.001 in StochasticLoadBalancer (the default load
balancer), while the default is 0.2 in other load balancers (i.e.,
SimpleLoadBalancer).</description>
</property>
<property>
<name>hbase.normalizer.period</name>
<value>300000</value>
<description>Period at which the region normalizer runs in the Master.</description>
<description>Period at which the region normalizer runs in the Master, in
milliseconds.</description>
</property>
<property>
<name>hbase.normalizer.split.enabled</name>
<value>true</value>
<description>Whether to split a region as part of normalization.</description>
</property>
<property>
<name>hbase.normalizer.merge.enabled</name>
<value>true</value>
<description>Whether to merge a region as part of normalization.</description>
</property>
<property>
<name>hbase.normalizer.min.region.count</name>
<value>3</value>
<description>configure the minimum number of regions</description>
<description>The minimum number of regions in a table to consider it for merge
normalization.</description>
</property>
<property>
<name>hbase.normalizer.min.region.merge.age</name>
<name>hbase.normalizer.merge.min_region_age.days</name>
<value>3</value>
<description>configure the minimum age in days for region before it is considered for merge while
normalizing</description>
<description>The minimum age for a region to be considered for a merge, in days.</description>
</property>
<property>
<name>hbase.regions.slop</name>
<value>0.001</value>
<description>Rebalance if any regionserver has average + (average * slop) regions.
The default value of this parameter is 0.001 in StochasticLoadBalancer (the default load balancer),
while the default is 0.2 in other load balancers (i.e., SimpleLoadBalancer).</description>
<name>hbase.normalizer.merge.min_region_age.days</name>
<value>3</value>
<description>The minimum age for a region to be considered for a merge, in days.</description>
</property>
<property>
<name>hbase.normalizer.merge.min_region_size.mb</name>
<value>1</value>
<description>The minimum size for a region to be considered for a merge, in whole
MBs.</description>
</property>
<property>
<name>hbase.server.thread.wakefrequency</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -400,6 +401,8 @@ public void run() {
private final LockManager lockManager = new LockManager(this);

private RSGroupBasedLoadBalancer balancer;
// a lock to prevent concurrent normalization actions.
private final ReentrantLock normalizationInProgressLock = new ReentrantLock();
saintstack marked this conversation as resolved.
Show resolved Hide resolved
private RegionNormalizer normalizer;
private BalancerChore balancerChore;
private RegionNormalizerChore normalizerChore;
Expand Down Expand Up @@ -795,12 +798,11 @@ protected void initializeZKBasedSystemTrackers()
throws IOException, InterruptedException, KeeperException, ReplicationException {
this.balancer = new RSGroupBasedLoadBalancer();
this.balancer.setConf(conf);
this.normalizer = RegionNormalizerFactory.getRegionNormalizer(conf);
this.normalizer.setMasterServices(this);
this.normalizer.setMasterRpcServices((MasterRpcServices)rpcServices);
saintstack marked this conversation as resolved.
Show resolved Hide resolved
this.loadBalancerTracker = new LoadBalancerTracker(zooKeeper, this);
this.loadBalancerTracker.start();

this.normalizer = RegionNormalizerFactory.getRegionNormalizer(conf);
this.normalizer.setMasterServices(this);
this.regionNormalizerTracker = new RegionNormalizerTracker(zooKeeper, this);
this.regionNormalizerTracker.start();

Expand Down Expand Up @@ -1887,17 +1889,16 @@ public List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans)
}

@Override
@VisibleForTesting
public RegionNormalizer getRegionNormalizer() {
return this.normalizer;
}

/**
* Perform normalization of cluster (invoked by {@link RegionNormalizerChore}).
*
* @return true if normalization step was performed successfully, false otherwise
* (specifically, if HMaster hasn't been initialized properly or normalization
* is globally disabled)
* @return true if an existing normalization was already in progress, or if a new normalization
* was performed successfully; false otherwise (specifically, if HMaster finished initializing
* or normalization is globally disabled).
*/
public boolean normalizeRegions() throws IOException {
if (regionNormalizerTracker == null || !regionNormalizerTracker.isNormalizerOn()) {
Expand All @@ -1911,34 +1912,42 @@ public boolean normalizeRegions() throws IOException {
return false;
}

synchronized (this.normalizer) {
if (!normalizationInProgressLock.tryLock()) {
ndimiduk marked this conversation as resolved.
Show resolved Hide resolved
saintstack marked this conversation as resolved.
Show resolved Hide resolved
// Don't run the normalizer concurrently
LOG.info("Normalization already in progress. Skipping request.");
return true;
}

List<TableName> allEnabledTables = new ArrayList<>(
this.tableStateManager.getTablesInStates(TableState.State.ENABLED));

try {
final List<TableName> allEnabledTables = new ArrayList<>(
tableStateManager.getTablesInStates(TableState.State.ENABLED));
Collections.shuffle(allEnabledTables);

for (TableName table : allEnabledTables) {
TableDescriptor tblDesc = getTableDescriptors().get(table);
if (table.isSystemTable() || (tblDesc != null &&
!tblDesc.isNormalizationEnabled())) {
LOG.trace("Skipping normalization for {}, as it's either system"
+ " table or doesn't have auto normalization turned on", table);
continue;
}
try (final Admin admin = asyncClusterConnection.toConnection().getAdmin()) {
for (TableName table : allEnabledTables) {
if (table.isSystemTable()) {
continue;
}
final TableDescriptor tblDesc = getTableDescriptors().get(table);
if (tblDesc != null && !tblDesc.isNormalizationEnabled()) {
LOG.debug("Skipping table {} because normalization is disabled in its"
+ " table properties.", table);
continue;
}

// make one last check that the cluster isn't shutting down before proceeding.
if (skipRegionManagementAction("region normalizer")) {
return false;
}
// make one last check that the cluster isn't shutting down before proceeding.
if (skipRegionManagementAction("region normalizer")) {
return false;
}

final List<NormalizationPlan> plans = this.normalizer.computePlanForTable(table);
if (CollectionUtils.isEmpty(plans)) {
return true;
}
final List<NormalizationPlan> plans = normalizer.computePlansForTable(table);
if (CollectionUtils.isEmpty(plans)) {
LOG.debug("No normalization required for table {}.", table);
continue;
}

try (final Admin admin = asyncClusterConnection.toConnection().getAdmin()) {
// as of this writing, `plan.execute()` is non-blocking, so there's no artificial rate-
// limiting of merge requests due to this serial loop.
for (NormalizationPlan plan : plans) {
plan.execute(admin);
if (plan.getType() == PlanType.SPLIT) {
Expand All @@ -1949,9 +1958,9 @@ public boolean normalizeRegions() throws IOException {
}
}
}
} finally {
normalizationInProgressLock.unlock();
}
// If Region did not generate any plans, it means the cluster is already balanced.
// Return true indicating a success.
return true;
}

Expand Down
Loading