5757import org .apache .hadoop .hbase .client .ResultScanner ;
5858import org .apache .hadoop .hbase .client .TableDescriptor ;
5959import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
60+ import org .apache .hadoop .hbase .client .TableState ;
6061import org .apache .hadoop .hbase .constraint .ConstraintException ;
6162import org .apache .hadoop .hbase .coprocessor .MultiRowMutationEndpoint ;
6263import 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 ) {
0 commit comments