Skip to content

Commit 2874f00

Browse files
authored
HBASE-24928 balanceRSGroup should skip generating balance plan for disabled table and splitParent region (#2292)
Signed-off-by: Viraj Jasani <[email protected]> Signed-off-by: Guanghao Zhang <[email protected]>
1 parent c3a58bf commit 2874f00

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.hadoop.hbase.client.ResultScanner;
5858
import org.apache.hadoop.hbase.client.TableDescriptor;
5959
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
60+
import org.apache.hadoop.hbase.client.TableState;
6061
import org.apache.hadoop.hbase.constraint.ConstraintException;
6162
import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint;
6263
import org.apache.hadoop.hbase.exceptions.DeserializationException;
@@ -1064,19 +1065,33 @@ private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName)
10641065
return rit;
10651066
}
10661067

1067-
private Map<TableName, Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsByTable(
1068-
String groupName) throws IOException {
1068+
/**
1069+
* This is an EXPENSIVE clone. Cloning though is the safest thing to do. Can't let out original
1070+
* since it can change and at least the load balancer wants to iterate this exported list. Load
1071+
* balancer should iterate over this list because cloned list will ignore disabled table and split
1072+
* parent region cases. This method is invoked by {@link #balanceRSGroup}
1073+
* @return A clone of current assignments for this group.
1074+
*/
1075+
@VisibleForTesting
1076+
Map<TableName, Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsByTable(
1077+
TableStateManager tableStateManager, String groupName) throws IOException {
10691078
Map<TableName, Map<ServerName, List<RegionInfo>>> result = Maps.newHashMap();
10701079
Set<TableName> tablesInGroupCache = new HashSet<>();
1071-
for (Map.Entry<RegionInfo, ServerName> entry :
1072-
masterServices.getAssignmentManager().getRegionStates()
1073-
.getRegionAssignments().entrySet()) {
1080+
for (Map.Entry<RegionInfo, ServerName> entry : masterServices.getAssignmentManager()
1081+
.getRegionStates().getRegionAssignments().entrySet()) {
10741082
RegionInfo region = entry.getKey();
10751083
TableName tn = region.getTable();
10761084
ServerName server = entry.getValue();
10771085
if (isTableInGroup(tn, groupName, tablesInGroupCache)) {
1086+
if (tableStateManager
1087+
.isTableState(tn, TableState.State.DISABLED, TableState.State.DISABLING)) {
1088+
continue;
1089+
}
1090+
if (region.isSplitParent()) {
1091+
continue;
1092+
}
10781093
result.computeIfAbsent(tn, k -> new HashMap<>())
1079-
.computeIfAbsent(server, k -> new ArrayList<>()).add(region);
1094+
.computeIfAbsent(server, k -> new ArrayList<>()).add(region);
10801095
}
10811096
}
10821097
RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
@@ -1087,7 +1102,6 @@ private Map<TableName, Map<ServerName, List<RegionInfo>>> getRSGroupAssignmentsB
10871102
}
10881103
}
10891104
}
1090-
10911105
return result;
10921106
}
10931107

@@ -1119,7 +1133,7 @@ public boolean balanceRSGroup(String groupName) throws IOException {
11191133

11201134
// We balance per group instead of per table
11211135
Map<TableName, Map<ServerName, List<RegionInfo>>> assignmentsByTable =
1122-
getRSGroupAssignmentsByTable(groupName);
1136+
getRSGroupAssignmentsByTable(masterServices.getTableStateManager(), groupName);
11231137
List<RegionPlan> plans = balancer.balanceCluster(assignmentsByTable);
11241138
boolean balancerRan = !plans.isEmpty();
11251139
if (balancerRan) {

hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBalance.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import org.apache.hadoop.hbase.HBaseClassTestRule;
27+
import org.apache.hadoop.hbase.HConstants;
2728
import org.apache.hadoop.hbase.NamespaceDescriptor;
2829
import org.apache.hadoop.hbase.ServerName;
2930
import org.apache.hadoop.hbase.TableName;
@@ -33,6 +34,7 @@
3334
import org.apache.hadoop.hbase.client.RegionInfo;
3435
import org.apache.hadoop.hbase.client.TableDescriptor;
3536
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
37+
import org.apache.hadoop.hbase.master.HMaster;
3638
import org.apache.hadoop.hbase.testclassification.MediumTests;
3739
import org.apache.hadoop.hbase.testclassification.RSGroupTests;
3840
import org.apache.hadoop.hbase.util.Bytes;
@@ -181,4 +183,19 @@ public boolean evaluate() throws Exception {
181183
});
182184
}
183185

186+
@Test public void testGetRSGroupAssignmentsByTable() throws Exception {
187+
final TableName tableName = TableName.valueOf(name.getMethodName());
188+
TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY, 10);
189+
// disable table
190+
final TableName disableTableName = TableName.valueOf("testDisableTable");
191+
TEST_UTIL.createMultiRegionTable(disableTableName, HConstants.CATALOG_FAMILY, 10);
192+
TEST_UTIL.getAdmin().disableTable(disableTableName);
193+
194+
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
195+
RSGroupInfoManagerImpl gm = (RSGroupInfoManagerImpl) master.getRSGroupInfoManager();
196+
Map<TableName, Map<ServerName, List<RegionInfo>>> assignments =
197+
gm.getRSGroupAssignmentsByTable(master.getTableStateManager(), RSGroupInfo.DEFAULT_GROUP);
198+
assertFalse(assignments.containsKey(disableTableName));
199+
assertTrue(assignments.containsKey(tableName));
200+
}
184201
}

0 commit comments

Comments
 (0)