HBASE-24928 balanceRSGroup should skip generating balance plan for disabled table and splitParent region (#2292)
Signed-off-by: Viraj Jasani <vjasani@apache.org> Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
parent
c3a58bfe49
commit
2874f00a2f
|
@ -57,6 +57,7 @@ import org.apache.hadoop.hbase.client.Result;
|
|||
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||
import org.apache.hadoop.hbase.client.TableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
|
||||
import org.apache.hadoop.hbase.client.TableState;
|
||||
import org.apache.hadoop.hbase.constraint.ConstraintException;
|
||||
import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint;
|
||||
import org.apache.hadoop.hbase.exceptions.DeserializationException;
|
||||
|
@ -1064,17 +1065,31 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
|||
return rit;
|
||||
}
|
||||
|
||||
private Map<TableName, Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsByTable(
|
||||
String groupName) throws IOException {
|
||||
/**
|
||||
* This is an EXPENSIVE clone. Cloning though is the safest thing to do. Can't let out original
|
||||
* since it can change and at least the load balancer wants to iterate this exported list. Load
|
||||
* balancer should iterate over this list because cloned list will ignore disabled table and split
|
||||
* parent region cases. This method is invoked by {@link #balanceRSGroup}
|
||||
* @return A clone of current assignments for this group.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
Map<TableName, Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsByTable(
|
||||
TableStateManager tableStateManager, String groupName) throws IOException {
|
||||
Map<TableName, Map<ServerName, List<RegionInfo>>> result = Maps.newHashMap();
|
||||
Set<TableName> tablesInGroupCache = new HashSet<>();
|
||||
for (Map.Entry<RegionInfo, ServerName> entry :
|
||||
masterServices.getAssignmentManager().getRegionStates()
|
||||
.getRegionAssignments().entrySet()) {
|
||||
for (Map.Entry<RegionInfo, ServerName> entry : masterServices.getAssignmentManager()
|
||||
.getRegionStates().getRegionAssignments().entrySet()) {
|
||||
RegionInfo region = entry.getKey();
|
||||
TableName tn = region.getTable();
|
||||
ServerName server = entry.getValue();
|
||||
if (isTableInGroup(tn, groupName, tablesInGroupCache)) {
|
||||
if (tableStateManager
|
||||
.isTableState(tn, TableState.State.DISABLED, TableState.State.DISABLING)) {
|
||||
continue;
|
||||
}
|
||||
if (region.isSplitParent()) {
|
||||
continue;
|
||||
}
|
||||
result.computeIfAbsent(tn, k -> new HashMap<>())
|
||||
.computeIfAbsent(server, k -> new ArrayList<>()).add(region);
|
||||
}
|
||||
|
@ -1087,7 +1102,6 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1119,7 +1133,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
|||
|
||||
// We balance per group instead of per table
|
||||
Map<TableName, Map<ServerName, List<RegionInfo>>> assignmentsByTable =
|
||||
getRSGroupAssignmentsByTable(groupName);
|
||||
getRSGroupAssignmentsByTable(masterServices.getTableStateManager(), groupName);
|
||||
List<RegionPlan> plans = balancer.balanceCluster(assignmentsByTable);
|
||||
boolean balancerRan = !plans.isEmpty();
|
||||
if (balancerRan) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.NamespaceDescriptor;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
|
@ -33,6 +34,7 @@ import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
|
|||
import org.apache.hadoop.hbase.client.RegionInfo;
|
||||
import org.apache.hadoop.hbase.client.TableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
|
||||
import org.apache.hadoop.hbase.master.HMaster;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.RSGroupTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
@ -181,4 +183,19 @@ public class TestRSGroupsBalance extends TestRSGroupsBase {
|
|||
});
|
||||
}
|
||||
|
||||
@Test public void testGetRSGroupAssignmentsByTable() 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();
|
||||
RSGroupInfoManagerImpl gm = (RSGroupInfoManagerImpl) master.getRSGroupInfoManager();
|
||||
Map<TableName, Map<ServerName, List<RegionInfo>>> assignments =
|
||||
gm.getRSGroupAssignmentsByTable(master.getTableStateManager(), RSGroupInfo.DEFAULT_GROUP);
|
||||
assertFalse(assignments.containsKey(disableTableName));
|
||||
assertTrue(assignments.containsKey(tableName));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue