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-23377 Balancer should skip disabled tables's regions #908

Merged
merged 3 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,8 @@ public boolean balance(boolean force) throws IOException {

boolean isByTable = getConfiguration().getBoolean("hbase.master.loadbalance.bytable", false);
Map<TableName, Map<ServerName, List<RegionInfo>>> assignments =
this.assignmentManager.getRegionStates().getAssignmentsForBalancer(isByTable);
this.assignmentManager.getRegionStates()
.getAssignmentsForBalancer(tableStateManager, isByTable);
for (Map<ServerName, List<RegionInfo>> serverMap : assignments.values()) {
serverMap.keySet().removeAll(this.serverManager.getDrainingServersList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ private void preTransitCheck(RegionStateNode regionNode, RegionState.State[] exp
if (!regionNode.isInState(expectedStates)) {
throw new DoNotRetryRegionException("Unexpected state for " + regionNode);
}
if (getTableStateManager().isTableState(regionNode.getTable(), TableState.State.DISABLING,
TableState.State.DISABLED)) {
if (isTableDisabled(regionNode.getTable())) {
throw new DoNotRetryIOException(regionNode.getTable() + " is disabled for " + regionNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.TableState;
import org.apache.hadoop.hbase.master.RegionState;
import org.apache.hadoop.hbase.master.RegionState.State;
import org.apache.hadoop.hbase.master.TableStateManager;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
Expand Down Expand Up @@ -537,10 +539,13 @@ public ServerName getRegionServerOfRegion(RegionInfo regionInfo) {
* @return A clone of current assignments.
*/
public Map<TableName, Map<ServerName, List<RegionInfo>>> getAssignmentsForBalancer(
boolean isByTable) {
TableStateManager tableStateManager, boolean isByTable) {
final Map<TableName, Map<ServerName, List<RegionInfo>>> result = new HashMap<>();
if (isByTable) {
for (RegionStateNode node : regionsMap.values()) {
if (isTableDisabled(tableStateManager, node.getTable())) {
continue;
}
Map<ServerName, List<RegionInfo>> tableResult =
result.computeIfAbsent(node.getTable(), t -> new HashMap<>());
final ServerName serverName = node.getRegionLocation();
Expand All @@ -561,14 +566,22 @@ public Map<TableName, Map<ServerName, List<RegionInfo>>> getAssignmentsForBalanc
} else {
final HashMap<ServerName, List<RegionInfo>> ensemble = new HashMap<>(serverMap.size());
for (ServerStateNode serverNode : serverMap.values()) {
ensemble.put(serverNode.getServerName(), serverNode.getRegionInfoList());
ensemble.put(serverNode.getServerName(), serverNode.getRegionInfoList().stream()
.filter(region -> !isTableDisabled(tableStateManager, region.getTable()))
.collect(Collectors.toList()));
}
// Use a fake table name to represent the whole cluster's assignments
result.put(HConstants.ENSEMBLE_TABLE_NAME, ensemble);
}
return result;
}

private boolean isTableDisabled(final TableStateManager tableStateManager,
final TableName tableName) {
return tableStateManager
.isTableState(tableName, TableState.State.DISABLED, TableState.State.DISABLING);
}

// ==========================================================================
// Region in transition helpers
// ==========================================================================
Expand Down