Skip to content

Commit

Permalink
HBASE-22695 Store the rsgroup of a table in table configuration (#426)
Browse files Browse the repository at this point in the history
Signed-off-by: Guanghao Zhang <[email protected]>
  • Loading branch information
Apache9 committed Aug 16, 2019
1 parent 7328f5d commit 80bc41f
Show file tree
Hide file tree
Showing 26 changed files with 610 additions and 809 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -987,4 +988,9 @@ public ColumnFamilyDescriptor getColumnFamily(byte[] name) {
protected ModifyableTableDescriptor getDelegateeForModification() {
return delegatee;
}

@Override
public Optional<String> getRegionServerGroup() {
return delegatee.getRegionServerGroup();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import org.apache.hadoop.hbase.HConstants;
Expand Down Expand Up @@ -183,6 +184,13 @@ public interface TableDescriptor {
@Deprecated
String getOwnerString();

/**
* Get the region server group this table belongs to. The regions of this table will be placed
* only on the region servers within this group. If not present, will be placed on
* {@link org.apache.hadoop.hbase.rsgroup.RSGroupInfo#DEFAULT_GROUP}.
*/
Optional<String> getRegionServerGroup();

/**
* Getter for accessing the metadata associated with the key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;
Expand Down Expand Up @@ -188,6 +189,9 @@ public class TableDescriptorBuilder {
private static final Bytes PRIORITY_KEY
= new Bytes(Bytes.toBytes(PRIORITY));

private static final Bytes RSGROUP_KEY =
new Bytes(Bytes.toBytes(RSGroupInfo.TABLE_DESC_PROP_GROUP));

/**
* Relative priority of the table used for rpc scheduling
*/
Expand Down Expand Up @@ -537,6 +541,11 @@ public TableDescriptorBuilder setReplicationScope(int scope) {
return this;
}

public TableDescriptorBuilder setRegionServerGroup(String group) {
desc.setValue(RSGROUP_KEY, new Bytes(Bytes.toBytes(group)));
return this;
}

public TableDescriptor build() {
return new ModifyableTableDescriptor(desc);
}
Expand Down Expand Up @@ -1577,6 +1586,16 @@ private static TableDescriptor parseFrom(final byte[] bytes)
public int getColumnFamilyCount() {
return families.size();
}

@Override
public Optional<String> getRegionServerGroup() {
Bytes value = values.get(RSGROUP_KEY);
if (value != null) {
return Optional.of(Bytes.toString(value.get(), value.getOffset(), value.getLength()));
} else {
return Optional.empty();
}
}
}

private static Optional<CoprocessorDescriptor> toCoprocessorDescriptor(String spec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,38 @@
public class RSGroupInfo {
public static final String DEFAULT_GROUP = "default";
public static final String NAMESPACE_DESC_PROP_GROUP = "hbase.rsgroup.name";
public static final String TABLE_DESC_PROP_GROUP = "hbase.rsgroup.name";

private final String name;
// Keep servers in a sorted set so has an expected ordering when displayed.
private final SortedSet<Address> servers;
// Keep tables sorted too.
/**
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
* the configuration of a table so this will be removed.
*/
@Deprecated
private final SortedSet<TableName> tables;

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

RSGroupInfo(String name, SortedSet<Address> servers) {
this.name = name;
this.servers = servers == null ? new TreeSet<>() : new TreeSet<>(servers);
this.tables = new TreeSet<>();
}

/**
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information for a table will be
* stored in the configuration of a table so this will be removed.
*/
@Deprecated
RSGroupInfo(String name, SortedSet<Address> servers, SortedSet<TableName> tables) {
this.name = name;
this.servers = (servers == null) ? new TreeSet<>() : new TreeSet<>(servers);
this.tables = (tables == null) ? new TreeSet<>() : new TreeSet<>(tables);
this.tables = (tables == null) ? new TreeSet<>() : new TreeSet<>(tables);
}

public RSGroupInfo(RSGroupInfo src) {
Expand Down Expand Up @@ -100,23 +117,46 @@ public boolean removeServer(Address hostPort) {

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

/**
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
* the configuration of a table so this will be removed.
*/
@Deprecated
public void addTable(TableName table) {
tables.add(table);
}

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

/**
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
* the configuration of a table so this will be removed.
*/
@Deprecated
public boolean containsTable(TableName table) {
return tables.contains(table);
}

/**
* @deprecated Since 3.0.0, will be removed in 4.0.0. The rsgroup information will be stored in
* the configuration of a table so this will be removed.
*/
@Deprecated
public boolean removeTable(TableName table) {
return tables.remove(table);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ private void warmUpRegion(ServerName server, RegionInfo region) {
// Replace with an async implementation from which you can get
// a success/failure result.
@VisibleForTesting
public void move(final byte[] encodedRegionName, byte[] destServerName) throws HBaseIOException {
public void move(final byte[] encodedRegionName, byte[] destServerName) throws IOException {
RegionState regionState = assignmentManager.getRegionStates().
getRegionState(Bytes.toString(encodedRegionName));

Expand Down Expand Up @@ -3555,7 +3555,7 @@ public long transitReplicationPeerSyncReplicationState(String peerId, SyncReplic
* @param servers Region servers to decommission.
*/
public void decommissionRegionServers(final List<ServerName> servers, final boolean offload)
throws HBaseIOException {
throws IOException {
List<ServerName> serversAdded = new ArrayList<>(servers.size());
// Place the decommission marker first.
String parentZnode = getZooKeeper().getZNodePaths().drainingZNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package org.apache.hadoop.hbase.master;

import edu.umd.cs.findbugs.annotations.Nullable;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.TableName;
Expand Down Expand Up @@ -65,95 +65,72 @@ public interface LoadBalancer extends Configurable, Stoppable, ConfigurationObse
ServerName BOGUS_SERVER_NAME = ServerName.valueOf("localhost,1,1");

/**
* Set the current cluster status. This allows a LoadBalancer to map host name to a server
* @param st
* Set the current cluster status. This allows a LoadBalancer to map host name to a server
*/
void setClusterMetrics(ClusterMetrics st);

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

/**
* Set the master service.
* @param masterServices
*/
void setMasterServices(MasterServices masterServices);

/**
* Perform the major balance operation
* @param tableName
* @param clusterState
* @return List of plans
*/
List<RegionPlan> balanceCluster(TableName tableName, Map<ServerName,
List<RegionInfo>> clusterState) throws HBaseIOException;
List<RegionPlan> balanceCluster(TableName tableName,
Map<ServerName, List<RegionInfo>> clusterState) throws IOException;

/**
* Perform the major balance operation
* @param clusterState
* @return List of plans
*/
List<RegionPlan> balanceCluster(Map<ServerName,
List<RegionInfo>> clusterState) throws HBaseIOException;
List<RegionPlan> balanceCluster(Map<ServerName, List<RegionInfo>> clusterState)
throws IOException;

/**
* Perform a Round Robin assignment of regions.
* @param regions
* @param servers
* @return Map of servername to regioninfos
*/
Map<ServerName, List<RegionInfo>> roundRobinAssignment(
List<RegionInfo> regions,
List<ServerName> servers
) throws HBaseIOException;
Map<ServerName, List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions,
List<ServerName> servers) throws IOException;

/**
* Assign regions to the previously hosting region server
* @param regions
* @param servers
* @return List of plans
*/
@Nullable
Map<ServerName, List<RegionInfo>> retainAssignment(
Map<RegionInfo, ServerName> regions,
List<ServerName> servers
) throws HBaseIOException;
Map<ServerName, List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions,
List<ServerName> servers) throws IOException;

/**
* Get a random region server from the list
* @param regionInfo Region for which this selection is being done.
* @param servers
* @return Servername
*/
ServerName randomAssignment(
RegionInfo regionInfo, List<ServerName> servers
) throws HBaseIOException;
ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws IOException;

/**
* Initialize the load balancer. Must be called after setters.
* @throws HBaseIOException
*/
void initialize() throws HBaseIOException;
void initialize() throws IOException;

/**
* Marks the region as online at balancer.
* @param regionInfo
* @param sn
*/
void regionOnline(RegionInfo regionInfo, ServerName sn);

/**
* Marks the region as offline at balancer.
* @param regionInfo
*/
void regionOffline(RegionInfo regionInfo);

/*
/**
* Notification that config has changed
* @param conf
*/
@Override
void onConfigurationChange(Configuration conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public TransitRegionStateProcedure[] createRoundRobinAssignProcedures(List<Regio
this.master.getServerManager().createDestinationServersList(serversToExclude));
// Return mid-method!
return createAssignProcedures(assignments);
} catch (HBaseIOException hioe) {
} catch (IOException hioe) {
LOG.warn("Failed roundRobinAssignment", hioe);
}
// If an error above, fall-through to this simpler assign. Last resort.
Expand Down Expand Up @@ -1986,7 +1986,7 @@ private void processAssignmentPlans(final HashMap<RegionInfo, RegionStateNode> r
}
try {
acceptPlan(regions, balancer.retainAssignment(retainMap, servers));
} catch (HBaseIOException e) {
} catch (IOException e) {
LOG.warn("unable to retain assignment", e);
addToPendingAssignment(regions, retainMap.keySet());
}
Expand All @@ -2001,7 +2001,7 @@ private void processAssignmentPlans(final HashMap<RegionInfo, RegionStateNode> r
}
try {
acceptPlan(regions, balancer.roundRobinAssignment(hris, servers));
} catch (HBaseIOException e) {
} catch (IOException e) {
LOG.warn("unable to round-robin assignment", e);
addToPendingAssignment(regions, hris);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.io.IOException;
import java.util.List;
import java.util.Set;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.net.Address;
import org.apache.yetus.audience.InterfaceAudience;

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

/**
* Gets {@code RSGroupInfo} for the given table's group.
*/
RSGroupInfo getRSGroupInfoOfTable(TableName tableName) throws IOException;

/**
* Move given set of servers to the specified target RegionServer group.
*/
void moveServers(Set<Address> servers, String targetGroup) throws IOException;

/**
* Move given set of tables to the specified target RegionServer group.
* This will unassign all of a table's region so it can be reassigned to the correct group.
*/
void moveTables(Set<TableName> tables, String targetGroup) throws IOException;

/**
* Creates a new RegionServer group with the given name.
*/
Expand Down Expand Up @@ -79,16 +66,6 @@ public interface RSGroupAdmin {
*/
RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException;

/**
* Move given set of servers and tables to the specified target RegionServer group.
* @param servers set of servers to move
* @param tables set of tables to move
* @param targetGroup the target group name
* @throws IOException if moving the server and tables fail
*/
void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
String targetGroup) throws IOException;

/**
* Remove decommissioned servers from rsgroup.
* 1. Sometimes we may find the server aborted due to some hardware failure and we must offline
Expand Down
Loading

0 comments on commit 80bc41f

Please sign in to comment.