Skip to content

Commit e4b1720

Browse files
committed
HBASE-22695 Store the rsgroup of a table in table configuration (#426)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
1 parent 59b8dc5 commit e4b1720

26 files changed

+610
-809
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collections;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.Optional;
2627
import java.util.Set;
2728
import java.util.stream.Collectors;
2829
import java.util.stream.Stream;
@@ -987,4 +988,9 @@ public ColumnFamilyDescriptor getColumnFamily(byte[] name) {
987988
protected ModifyableTableDescriptor getDelegateeForModification() {
988989
return delegatee;
989990
}
991+
992+
@Override
993+
public Optional<String> getRegionServerGroup() {
994+
return delegatee.getRegionServerGroup();
995+
}
990996
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Comparator;
2424
import java.util.Iterator;
2525
import java.util.Map;
26+
import java.util.Optional;
2627
import java.util.Set;
2728
import java.util.stream.Stream;
2829
import org.apache.hadoop.hbase.HConstants;
@@ -183,6 +184,13 @@ public interface TableDescriptor {
183184
@Deprecated
184185
String getOwnerString();
185186

187+
/**
188+
* Get the region server group this table belongs to. The regions of this table will be placed
189+
* only on the region servers within this group. If not present, will be placed on
190+
* {@link org.apache.hadoop.hbase.rsgroup.RSGroupInfo#DEFAULT_GROUP}.
191+
*/
192+
Optional<String> getRegionServerGroup();
193+
186194
/**
187195
* Getter for accessing the metadata associated with the key.
188196
*

hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hadoop.hbase.HConstants;
4040
import org.apache.hadoop.hbase.TableName;
4141
import org.apache.hadoop.hbase.exceptions.DeserializationException;
42+
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
4243
import org.apache.hadoop.hbase.security.User;
4344
import org.apache.hadoop.hbase.util.Bytes;
4445
import org.apache.yetus.audience.InterfaceAudience;
@@ -188,6 +189,9 @@ public class TableDescriptorBuilder {
188189
private static final Bytes PRIORITY_KEY
189190
= new Bytes(Bytes.toBytes(PRIORITY));
190191

192+
private static final Bytes RSGROUP_KEY =
193+
new Bytes(Bytes.toBytes(RSGroupInfo.TABLE_DESC_PROP_GROUP));
194+
191195
/**
192196
* Relative priority of the table used for rpc scheduling
193197
*/
@@ -537,6 +541,11 @@ public TableDescriptorBuilder setReplicationScope(int scope) {
537541
return this;
538542
}
539543

544+
public TableDescriptorBuilder setRegionServerGroup(String group) {
545+
desc.setValue(RSGROUP_KEY, new Bytes(Bytes.toBytes(group)));
546+
return this;
547+
}
548+
540549
public TableDescriptor build() {
541550
return new ModifyableTableDescriptor(desc);
542551
}
@@ -1577,6 +1586,16 @@ private static TableDescriptor parseFrom(final byte[] bytes)
15771586
public int getColumnFamilyCount() {
15781587
return families.size();
15791588
}
1589+
1590+
@Override
1591+
public Optional<String> getRegionServerGroup() {
1592+
Bytes value = values.get(RSGROUP_KEY);
1593+
if (value != null) {
1594+
return Optional.of(Bytes.toString(value.get(), value.getOffset(), value.getLength()));
1595+
} else {
1596+
return Optional.empty();
1597+
}
1598+
}
15801599
}
15811600

15821601
private static Optional<CoprocessorDescriptor> toCoprocessorDescriptor(String spec) {

hbase-common/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfo.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,38 @@
3434
public class RSGroupInfo {
3535
public static final String DEFAULT_GROUP = "default";
3636
public static final String NAMESPACE_DESC_PROP_GROUP = "hbase.rsgroup.name";
37+
public static final String TABLE_DESC_PROP_GROUP = "hbase.rsgroup.name";
3738

3839
private final String name;
3940
// Keep servers in a sorted set so has an expected ordering when displayed.
4041
private final SortedSet<Address> servers;
4142
// Keep tables sorted too.
43+
/**
44+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
45+
* the configuration of a table so this will be removed.
46+
*/
47+
@Deprecated
4248
private final SortedSet<TableName> tables;
4349

4450
public RSGroupInfo(String name) {
4551
this(name, new TreeSet<Address>(), new TreeSet<TableName>());
4652
}
4753

54+
RSGroupInfo(String name, SortedSet<Address> servers) {
55+
this.name = name;
56+
this.servers = servers == null ? new TreeSet<>() : new TreeSet<>(servers);
57+
this.tables = new TreeSet<>();
58+
}
59+
60+
/**
61+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information for a table will be
62+
* stored in the configuration of a table so this will be removed.
63+
*/
64+
@Deprecated
4865
RSGroupInfo(String name, SortedSet<Address> servers, SortedSet<TableName> tables) {
4966
this.name = name;
5067
this.servers = (servers == null) ? new TreeSet<>() : new TreeSet<>(servers);
51-
this.tables = (tables == null) ? new TreeSet<>() : new TreeSet<>(tables);
68+
this.tables = (tables == null) ? new TreeSet<>() : new TreeSet<>(tables);
5269
}
5370

5471
public RSGroupInfo(RSGroupInfo src) {
@@ -100,23 +117,46 @@ public boolean removeServer(Address hostPort) {
100117

101118
/**
102119
* Get set of tables that are members of the group.
120+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
121+
* the configuration of a table so this will be removed.
103122
*/
123+
@Deprecated
104124
public SortedSet<TableName> getTables() {
105125
return tables;
106126
}
107127

128+
/**
129+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
130+
* the configuration of a table so this will be removed.
131+
*/
132+
@Deprecated
108133
public void addTable(TableName table) {
109134
tables.add(table);
110135
}
111136

137+
/**
138+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
139+
* the configuration of a table so this will be removed.
140+
*/
141+
@Deprecated
112142
public void addAllTables(Collection<TableName> arg) {
113143
tables.addAll(arg);
114144
}
115145

146+
/**
147+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
148+
* the configuration of a table so this will be removed.
149+
*/
150+
@Deprecated
116151
public boolean containsTable(TableName table) {
117152
return tables.contains(table);
118153
}
119154

155+
/**
156+
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
157+
* the configuration of a table so this will be removed.
158+
*/
159+
@Deprecated
120160
public boolean removeTable(TableName table) {
121161
return tables.remove(table);
122162
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ private void warmUpRegion(ServerName server, RegionInfo region) {
19561956
// Replace with an async implementation from which you can get
19571957
// a success/failure result.
19581958
@VisibleForTesting
1959-
public void move(final byte[] encodedRegionName, byte[] destServerName) throws HBaseIOException {
1959+
public void move(final byte[] encodedRegionName, byte[] destServerName) throws IOException {
19601960
RegionState regionState = assignmentManager.getRegionStates().
19611961
getRegionState(Bytes.toString(encodedRegionName));
19621962

@@ -3550,7 +3550,7 @@ public long transitReplicationPeerSyncReplicationState(String peerId, SyncReplic
35503550
* @param servers Region servers to decommission.
35513551
*/
35523552
public void decommissionRegionServers(final List<ServerName> servers, final boolean offload)
3553-
throws HBaseIOException {
3553+
throws IOException {
35543554
List<ServerName> serversAdded = new ArrayList<>(servers.size());
35553555
// Place the decommission marker first.
35563556
String parentZnode = getZooKeeper().getZNodePaths().drainingZNode;

hbase-server/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
package org.apache.hadoop.hbase.master;
2020

2121
import edu.umd.cs.findbugs.annotations.Nullable;
22+
import java.io.IOException;
2223
import java.util.List;
2324
import java.util.Map;
2425
import org.apache.hadoop.conf.Configurable;
2526
import org.apache.hadoop.conf.Configuration;
2627
import org.apache.hadoop.hbase.ClusterMetrics;
27-
import org.apache.hadoop.hbase.HBaseIOException;
2828
import org.apache.hadoop.hbase.ServerName;
2929
import org.apache.hadoop.hbase.Stoppable;
3030
import org.apache.hadoop.hbase.TableName;
@@ -65,95 +65,72 @@ public interface LoadBalancer extends Configurable, Stoppable, ConfigurationObse
6565
ServerName BOGUS_SERVER_NAME = ServerName.valueOf("localhost,1,1");
6666

6767
/**
68-
* Set the current cluster status. This allows a LoadBalancer to map host name to a server
69-
* @param st
68+
* Set the current cluster status. This allows a LoadBalancer to map host name to a server
7069
*/
7170
void setClusterMetrics(ClusterMetrics st);
7271

7372
/**
7473
* Pass RegionStates and allow balancer to set the current cluster load.
75-
* @param ClusterLoad
7674
*/
7775
void setClusterLoad(Map<TableName, Map<ServerName, List<RegionInfo>>> ClusterLoad);
7876

7977
/**
8078
* Set the master service.
81-
* @param masterServices
8279
*/
8380
void setMasterServices(MasterServices masterServices);
8481

8582
/**
8683
* Perform the major balance operation
87-
* @param tableName
88-
* @param clusterState
8984
* @return List of plans
9085
*/
91-
List<RegionPlan> balanceCluster(TableName tableName, Map<ServerName,
92-
List<RegionInfo>> clusterState) throws HBaseIOException;
86+
List<RegionPlan> balanceCluster(TableName tableName,
87+
Map<ServerName, List<RegionInfo>> clusterState) throws IOException;
9388

9489
/**
9590
* Perform the major balance operation
96-
* @param clusterState
9791
* @return List of plans
9892
*/
99-
List<RegionPlan> balanceCluster(Map<ServerName,
100-
List<RegionInfo>> clusterState) throws HBaseIOException;
93+
List<RegionPlan> balanceCluster(Map<ServerName, List<RegionInfo>> clusterState)
94+
throws IOException;
10195

10296
/**
10397
* Perform a Round Robin assignment of regions.
104-
* @param regions
105-
* @param servers
10698
* @return Map of servername to regioninfos
10799
*/
108-
Map<ServerName, List<RegionInfo>> roundRobinAssignment(
109-
List<RegionInfo> regions,
110-
List<ServerName> servers
111-
) throws HBaseIOException;
100+
Map<ServerName, List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions,
101+
List<ServerName> servers) throws IOException;
112102

113103
/**
114104
* Assign regions to the previously hosting region server
115-
* @param regions
116-
* @param servers
117105
* @return List of plans
118106
*/
119107
@Nullable
120-
Map<ServerName, List<RegionInfo>> retainAssignment(
121-
Map<RegionInfo, ServerName> regions,
122-
List<ServerName> servers
123-
) throws HBaseIOException;
108+
Map<ServerName, List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions,
109+
List<ServerName> servers) throws IOException;
124110

125111
/**
126112
* Get a random region server from the list
127113
* @param regionInfo Region for which this selection is being done.
128-
* @param servers
129-
* @return Servername
130114
*/
131-
ServerName randomAssignment(
132-
RegionInfo regionInfo, List<ServerName> servers
133-
) throws HBaseIOException;
115+
ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws IOException;
134116

135117
/**
136118
* Initialize the load balancer. Must be called after setters.
137-
* @throws HBaseIOException
138119
*/
139-
void initialize() throws HBaseIOException;
120+
void initialize() throws IOException;
140121

141122
/**
142123
* Marks the region as online at balancer.
143-
* @param regionInfo
144-
* @param sn
145124
*/
146125
void regionOnline(RegionInfo regionInfo, ServerName sn);
147126

148127
/**
149128
* Marks the region as offline at balancer.
150-
* @param regionInfo
151129
*/
152130
void regionOffline(RegionInfo regionInfo);
153131

154-
/*
132+
/**
155133
* Notification that config has changed
156-
* @param conf
157134
*/
158135
@Override
159136
void onConfigurationChange(Configuration conf);

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ public TransitRegionStateProcedure[] createRoundRobinAssignProcedures(List<Regio
683683
this.master.getServerManager().createDestinationServersList(serversToExclude));
684684
// Return mid-method!
685685
return createAssignProcedures(assignments);
686-
} catch (HBaseIOException hioe) {
686+
} catch (IOException hioe) {
687687
LOG.warn("Failed roundRobinAssignment", hioe);
688688
}
689689
// If an error above, fall-through to this simpler assign. Last resort.
@@ -1986,7 +1986,7 @@ private void processAssignmentPlans(final HashMap<RegionInfo, RegionStateNode> r
19861986
}
19871987
try {
19881988
acceptPlan(regions, balancer.retainAssignment(retainMap, servers));
1989-
} catch (HBaseIOException e) {
1989+
} catch (IOException e) {
19901990
LOG.warn("unable to retain assignment", e);
19911991
addToPendingAssignment(regions, retainMap.keySet());
19921992
}
@@ -2001,7 +2001,7 @@ private void processAssignmentPlans(final HashMap<RegionInfo, RegionStateNode> r
20012001
}
20022002
try {
20032003
acceptPlan(regions, balancer.roundRobinAssignment(hris, servers));
2004-
} catch (HBaseIOException e) {
2004+
} catch (IOException e) {
20052005
LOG.warn("unable to round-robin assignment", e);
20062006
addToPendingAssignment(regions, hris);
20072007
}

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.io.IOException;
2121
import java.util.List;
2222
import java.util.Set;
23-
24-
import org.apache.hadoop.hbase.TableName;
2523
import org.apache.hadoop.hbase.net.Address;
2624
import org.apache.yetus.audience.InterfaceAudience;
2725

@@ -35,22 +33,11 @@ public interface RSGroupAdmin {
3533
*/
3634
RSGroupInfo getRSGroupInfo(String groupName) throws IOException;
3735

38-
/**
39-
* Gets {@code RSGroupInfo} for the given table's group.
40-
*/
41-
RSGroupInfo getRSGroupInfoOfTable(TableName tableName) throws IOException;
42-
4336
/**
4437
* Move given set of servers to the specified target RegionServer group.
4538
*/
4639
void moveServers(Set<Address> servers, String targetGroup) throws IOException;
4740

48-
/**
49-
* Move given set of tables to the specified target RegionServer group.
50-
* This will unassign all of a table's region so it can be reassigned to the correct group.
51-
*/
52-
void moveTables(Set<TableName> tables, String targetGroup) throws IOException;
53-
5441
/**
5542
* Creates a new RegionServer group with the given name.
5643
*/
@@ -79,16 +66,6 @@ public interface RSGroupAdmin {
7966
*/
8067
RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException;
8168

82-
/**
83-
* Move given set of servers and tables to the specified target RegionServer group.
84-
* @param servers set of servers to move
85-
* @param tables set of tables to move
86-
* @param targetGroup the target group name
87-
* @throws IOException if moving the server and tables fail
88-
*/
89-
void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
90-
String targetGroup) throws IOException;
91-
9269
/**
9370
* Remove decommissioned servers from rsgroup.
9471
* 1. Sometimes we may find the server aborted due to some hardware failure and we must offline

0 commit comments

Comments
 (0)