Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package org.apache.hadoop.hbase.rsgroup;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
Expand All @@ -41,18 +45,22 @@ public class RSGroupInfo {
// Keep tables sorted too.
private final SortedSet<TableName> tables;

private final Map<String, String> configuration;

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

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);
configuration = new HashMap<>();
}

public RSGroupInfo(RSGroupInfo src) {
this(src.name, src.servers, src.tables);
src.configuration.forEach(this::setConfiguration);
}

/**
Expand Down Expand Up @@ -121,6 +129,30 @@ public boolean removeTable(TableName table) {
return tables.remove(table);
}

/**
* Getter for fetching an unmodifiable {@link #configuration} map.
*/
public Map<String, String> getConfiguration() {
// shallow pointer copy
return Collections.unmodifiableMap(configuration);
}

/**
* Setter for storing a configuration setting in {@link #configuration} map.
* @param key Config key.
* @param value String value.
*/
public void setConfiguration(String key, String value) {
configuration.put(key, Objects.requireNonNull(value));
}

/**
* Remove a config setting represented by the key from the {@link #configuration} map
*/
public void removeConfiguration(final String key) {
configuration.remove(key);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
1 change: 1 addition & 0 deletions hbase-protocol/src/main/protobuf/RSGroup.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ message RSGroupInfo {
required string name = 1;
repeated ServerName servers = 4;
repeated TableName tables = 3;
repeated NameStringPair configuration = 5;
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.hadoop.hbase.TableName;
Expand Down Expand Up @@ -105,4 +106,12 @@ void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
* @param newName new rsgroup name
*/
void renameRSGroup(String oldName, String newName) throws IOException;

/**
* Update RSGroup configuration
* @param groupName the group name
* @param configuration new configuration of the group name to be set
* @throws IOException if a remote or network exception occurs
*/
void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.hadoop.hbase.TableName;
Expand All @@ -31,6 +32,7 @@
import org.apache.hadoop.hbase.net.Address;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.AddRSGroupRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.BalanceRSGroupRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.GetRSGroupInfoOfServerRequest;
Expand All @@ -47,6 +49,7 @@
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGroupRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RenameRSGroupRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.UpdateRSGroupConfigRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos;
import org.apache.yetus.audience.InterfaceAudience;

Expand Down Expand Up @@ -249,4 +252,21 @@ public void renameRSGroup(String oldName, String newName) throws IOException {
throw ProtobufUtil.handleRemoteException(e);
}
}

@Override
public void updateRSGroupConfig(String groupName, Map<String, String> configuration)
throws IOException {
UpdateRSGroupConfigRequest.Builder builder = UpdateRSGroupConfigRequest.newBuilder()
.setGroupName(groupName);
if (configuration != null) {
configuration.entrySet().forEach(e ->
builder.addConfiguration(NameStringPair.newBuilder().setName(e.getKey())
.setValue(e.getValue()).build()));
}
try {
stub.updateRSGroupConfig(null, builder.build());
} catch (ServiceException e) {
throw ProtobufUtil.handleRemoteException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,6 +82,8 @@
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersResponse;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RenameRSGroupRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RenameRSGroupResponse;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.UpdateRSGroupConfigRequest;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.UpdateRSGroupConfigResponse;
import org.apache.hadoop.hbase.protobuf.generated.TableProtos;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.UserProvider;
Expand All @@ -90,6 +93,8 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;

// TODO: Encapsulate MasterObserver functions into separate subclass.
Expand Down Expand Up @@ -425,6 +430,29 @@ public void renameRSGroup(RpcController controller,
}
done.run(builder.build());
}

@Override
public void updateRSGroupConfig(RpcController controller, UpdateRSGroupConfigRequest request,
RpcCallback<UpdateRSGroupConfigResponse> done) {
UpdateRSGroupConfigResponse.Builder builder = UpdateRSGroupConfigResponse.newBuilder();
String groupName = request.getGroupName();
Map<String, String> configuration = Maps.newHashMap();
request.getConfigurationList().forEach(p -> configuration.put(p.getName(), p.getValue()));
LOG.info("{} update rsgroup {} configuration {}", master.getClientIdAuditPrefix(), groupName,
configuration);
try {
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().preUpdateRSGroupConfig(groupName, configuration);
}
groupAdminServer.updateRSGroupConfig(groupName, configuration);
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().postUpdateRSGroupConfig(groupName, configuration);
}
} catch (IOException e) {
CoprocessorRpcUtils.setControllerException(controller, e);
}
done.run(builder.build());
}
}

boolean rsgroupHasServersOnline(TableDescriptor desc) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ public void renameRSGroup(String oldName, String newName) throws IOException {
}
}

@Override
public void updateRSGroupConfig(String groupName, Map<String, String> configuration)
throws IOException {
synchronized (rsGroupInfoManager) {
rsGroupInfoManager.updateRSGroupConfig(groupName, configuration);
}
}

private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName)
throws IOException {
Map<String, RegionState> rit = Maps.newTreeMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.hadoop.hbase.NamespaceDescriptor;
Expand Down Expand Up @@ -139,4 +140,12 @@ void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
* @return {@link RSGroupInfo} which table should belong to
*/
RSGroupInfo determineRSGroupInfoForTable(TableName tableName) throws IOException;

/**
* Update RSGroup configuration
* @param groupName the group name
* @param configuration new configuration of the group name to be set
* @throws IOException if a remote or network exception occurs
*/
void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.DoNotRetryIOException;
Expand Down Expand Up @@ -452,6 +454,16 @@ public RSGroupInfo determineRSGroupInfoForTable(TableName tableName)
return getRSGroup(RSGroupInfo.DEFAULT_GROUP);
}

@Override
public void updateRSGroupConfig(String groupName, Map<String, String> configuration)
throws IOException {
RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
new HashSet<>(rsGroupInfo.getConfiguration().keySet())
.forEach(rsGroupInfo::removeConfiguration);
configuration.forEach(rsGroupInfo::setConfiguration);
flushConfig();
}

List<RSGroupInfo> retrieveGroupListFromGroupTable() throws IOException {
List<RSGroupInfo> rsGroupInfoList = Lists.newArrayList();
try (Table table = conn.getTable(RSGROUP_TABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.net.Address;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos;
import org.apache.hadoop.hbase.protobuf.generated.TableProtos;
import org.apache.yetus.audience.InterfaceAudience;
Expand All @@ -35,14 +37,16 @@ private RSGroupProtobufUtil() {
}

static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName());
RSGroupInfo rsGroupInfo = new RSGroupInfo(proto.getName());
for(HBaseProtos.ServerName el: proto.getServersList()) {
RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
rsGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
}
for(TableProtos.TableName pTableName: proto.getTablesList()) {
RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
rsGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
}
return RSGroupInfo;
proto.getConfigurationList().forEach(pair ->
rsGroupInfo.setConfiguration(pair.getName(), pair.getValue()));
return rsGroupInfo;
}

static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
Expand All @@ -57,8 +61,11 @@ static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
.setPort(el.getPort())
.build());
}
List<NameStringPair> configuration = pojo.getConfiguration().entrySet()
.stream().map(entry -> NameStringPair.newBuilder()
.setName(entry.getKey()).setValue(entry.getValue()).build())
.collect(Collectors.toList());
return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName())
.addAllServers(hostports)
.addAllTables(tables).build();
.addAllServers(hostports).addAllTables(tables).addAllConfiguration(configuration).build();
}
}
11 changes: 11 additions & 0 deletions hbase-rsgroup/src/main/protobuf/RSGroupAdmin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ message RenameRSGroupRequest {
message RenameRSGroupResponse {
}

message UpdateRSGroupConfigRequest {
required string group_name = 1;
repeated NameStringPair configuration = 2;
}

message UpdateRSGroupConfigResponse {
}

service RSGroupAdminService {
rpc GetRSGroupInfo(GetRSGroupInfoRequest)
returns (GetRSGroupInfoResponse);
Expand Down Expand Up @@ -167,4 +175,7 @@ service RSGroupAdminService {

rpc RenameRSGroup(RenameRSGroupRequest)
returns (RenameRSGroupResponse);

rpc UpdateRSGroupConfig(UpdateRSGroupConfigRequest)
returns (UpdateRSGroupConfigResponse);
}
Loading