HBASE-23377 Balancer should skip disabled tables's regions (#908)

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
Signed-off-by: GuangxuCheng  <guangxucheng@gmail.com>
Signed-off-by Anoop Sam John <anoopsamjohn@apache.org>
Signed-off-by: Reid Chan <reidchan@apache.org>
This commit is contained in:
binlijin 2019-12-10 19:28:42 +08:00 committed by GitHub
parent 82e155eb26
commit f87428e704
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 5 deletions

View File

@ -1796,7 +1796,8 @@ public class HMaster extends HRegionServer implements MasterServices {
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());
}

View File

@ -581,8 +581,7 @@ public class AssignmentManager {
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);
}
}

View File

@ -37,8 +37,10 @@ import org.apache.hadoop.hbase.HRegionLocation;
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;
@ -537,10 +539,13 @@ public class RegionStates {
* @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();
@ -561,7 +566,9 @@ public class RegionStates {
} 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);
@ -569,6 +576,12 @@ public class RegionStates {
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
// ==========================================================================

View File

@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.master;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.master.assignment.AssignmentManager;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
/**
* Test balancer with disabled table
*/
@Category({ MasterTests.class, LargeTests.class })
public class TestBalancerWithDisabledTable {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBalancerWithDisabledTable.class);
private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@Rule
public TestName name = new TestName();
@Before
public void before() throws Exception {
TEST_UTIL.startMiniCluster();
}
@After
public void after() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@Test
public void testAssignmentsForBalancer() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY, 10);
// disable table
final TableName disableTableName = TableName.valueOf("testDisableTable");
TEST_UTIL.createMultiRegionTable(disableTableName, HConstants.CATALOG_FAMILY, 10);
TEST_UTIL.getAdmin().disableTable(disableTableName);
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
AssignmentManager assignmentManager = master.getAssignmentManager();
TableStateManager tableStateManager = master.getTableStateManager();
Map<TableName, Map<ServerName, List<RegionInfo>>> assignments =
assignmentManager.getRegionStates().getAssignmentsForBalancer(tableStateManager, true);
assertFalse(assignments.containsKey(disableTableName));
assertTrue(assignments.containsKey(tableName));
assignments =
assignmentManager.getRegionStates().getAssignmentsForBalancer(tableStateManager, false);
Map<TableName, Map<ServerName, List<RegionInfo>>> tableNameMap = new HashMap<>();
for (Map.Entry<ServerName, List<RegionInfo>> entry : assignments
.get(HConstants.ENSEMBLE_TABLE_NAME).entrySet()) {
final ServerName serverName = entry.getKey();
for (RegionInfo regionInfo : entry.getValue()) {
Map<ServerName, List<RegionInfo>> tableResult =
tableNameMap.computeIfAbsent(regionInfo.getTable(), t -> new HashMap<>());
List<RegionInfo> serverResult =
tableResult.computeIfAbsent(serverName, s -> new ArrayList<>());
serverResult.add(regionInfo);
}
}
assertFalse(tableNameMap.containsKey(disableTableName));
assertTrue(tableNameMap.containsKey(tableName));
}
}