HBASE-24112 [RSGroup] Support renaming rsgroup (#1467)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Reid Chan 2020-04-15 19:20:14 +08:00 committed by GitHub
parent 03d73f151b
commit 0d8683507b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1395 additions and 28 deletions

View File

@ -123,6 +123,14 @@ message RemoveServersRequest {
message RemoveServersResponse {
}
message RenameRSGroupRequest {
required string old_rsgroup_name = 1;
required string new_rsgroup_name = 2;
}
message RenameRSGroupResponse {
}
service RSGroupAdminService {
rpc GetRSGroupInfo(GetRSGroupInfoRequest)
returns (GetRSGroupInfoResponse);
@ -156,4 +164,7 @@ service RSGroupAdminService {
rpc RemoveServers(RemoveServersRequest)
returns (RemoveServersResponse);
rpc RenameRSGroup(RenameRSGroupRequest)
returns (RenameRSGroupResponse);
}

View File

@ -99,4 +99,11 @@ public interface RSGroupAdmin extends Closeable {
* @param servers set of servers to remove
*/
void removeServers(Set<Address> servers) throws IOException;
/**
* Rename rsgroup.
* @param oldName old rsgroup name
* @param newName new rsgroup name
*/
void renameRSGroup(String oldName, String newName) throws IOException;
}

View File

@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.MoveTablesR
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RSGroupAdminService;
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.RSGroupProtos;
import com.google.common.collect.Sets;
@ -226,6 +227,18 @@ public class RSGroupAdminClient implements RSGroupAdmin {
}
}
@Override
public void renameRSGroup(String oldName, String newName) throws IOException {
RenameRSGroupRequest request = RenameRSGroupRequest.newBuilder()
.setOldRsgroupName(oldName)
.setNewRsgroupName(newName).build();
try {
stub.renameRSGroup(null, request);
} catch (ServiceException e) {
throw ProtobufUtil.handleRemoteException(e);
}
}
@Override
public void close() throws IOException {
}

View File

@ -88,6 +88,8 @@ import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGro
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGroupResponse;
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersRequest;
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.TableProtos;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.UserProvider;
@ -489,6 +491,27 @@ public class RSGroupAdminEndpoint extends RSGroupAdminService
}
}
@Override
public void renameRSGroup(RpcController controller,
RenameRSGroupRequest request,
RpcCallback<RenameRSGroupResponse> done) {
RenameRSGroupResponse.Builder builder = RenameRSGroupResponse.newBuilder();
String oldRSGroup = request.getOldRsgroupName();
String newRSGroup = request.getNewRsgroupName();
try {
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().preRenameRSGroup(oldRSGroup, newRSGroup);
}
groupAdminServer.renameRSGroup(oldRSGroup, newRSGroup);
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().postRenameRSGroup(oldRSGroup, newRSGroup);
}
} catch (IOException e) {
ResponseConverter.setControllerException(controller, e);
}
done.run(builder.build());
}
/////////////////////////////////////////////////////////////////////////////
// MasterObserver overrides
/////////////////////////////////////////////////////////////////////////////
@ -1231,6 +1254,16 @@ public class RSGroupAdminEndpoint extends RSGroupAdminService
}
@Override
public void preRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
@Override
public void postRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
public void checkPermission(String request) throws IOException {
accessChecker.requirePermission(getActiveUser(), request, Permission.Action.ADMIN);
}

View File

@ -503,6 +503,13 @@ public class RSGroupAdminServer implements RSGroupAdmin {
moveTables(tables, targetGroup);
}
@Override
public void renameRSGroup(String oldName, String newName) throws IOException {
synchronized (rsGroupInfoManager) {
rsGroupInfoManager.renameRSGroup(oldName, newName);
}
}
@Override
public void close() throws IOException {
}

View File

@ -125,4 +125,11 @@ public interface RSGroupInfoManager {
* @param servers set of servers to remove
*/
void removeServers(Set<Address> servers) throws IOException;
/**
* Rename RSGroup
* @param oldName old rsgroup name
* @param newName new rsgroup name
*/
void renameRSGroup(String oldName, String newName) throws IOException;
}

View File

@ -842,4 +842,21 @@ public class RSGroupInfoManagerImpl implements RSGroupInfoManager, ServerListene
flushConfig(newGroupMap);
}
}
@Override
public void renameRSGroup(String oldName, String newName) throws IOException {
checkGroupName(oldName);
checkGroupName(newName);
if (oldName.equals(RSGroupInfo.DEFAULT_GROUP)) {
throw new ConstraintException("Can't rename default rsgroup");
}
RSGroupInfo oldGroup = getRSGroup(oldName);
Map<String,RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
newGroupMap.remove(oldName);
RSGroupInfo newGroup = new RSGroupInfo(newName, oldGroup.getServers(), oldGroup.getTables());
newGroupMap.put(newName, newGroup);
flushConfig(newGroupMap);
}
}

View File

@ -470,4 +470,52 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
initialize();
}
@Test
public void testRenameRSGroup() throws Exception {
// Add rsgroup, and assign 2 servers and a table to it.
RSGroupInfo oldgroup = addGroup(rsGroupAdmin, "oldgroup", 2);
final TableName tb1 = TableName.valueOf("testRename");
TEST_UTIL.createTable(tb1, "tr");
rsGroupAdmin.moveTables(Sets.newHashSet(tb1), oldgroup.getName());
TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return rsGroupAdmin.getRSGroupInfoOfTable(tb1).getServers().size() == 2;
}
});
oldgroup = rsGroupAdmin.getRSGroupInfo(oldgroup.getName());
assertEquals(2, oldgroup.getServers().size());
assertEquals(oldgroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tb1).getName());
assertTrue(oldgroup.getTables().contains(tb1));
// Another rsgroup and table for verification
// that they are unchanged during we're renaming oldgroup.
RSGroupInfo normal = addGroup(rsGroupAdmin, "normal", 1);
final TableName tb2 = TableName.valueOf("unmovedTable");
TEST_UTIL.createTable(tb2, "ut");
rsGroupAdmin.moveTables(Sets.newHashSet(tb2), normal.getName());
TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return rsGroupAdmin.getRSGroupInfoOfTable(tb2).getServers().size() == 1;
}
});
normal = rsGroupAdmin.getRSGroupInfo(normal.getName());
assertEquals(1, normal.getServers().size());
assertEquals(normal.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tb2).getName());
assertTrue(normal.containsTable(tb2));
// Rename rsgroup
rsGroupAdmin.renameRSGroup(oldgroup.getName(), "newgroup");
Set<Address> servers = oldgroup.getServers();
RSGroupInfo newgroup = rsGroupAdmin.getRSGroupInfo("newgroup");
assertEquals(servers.size(), newgroup.getServers().size());
for (Address server : servers) {
assertTrue(newgroup.containsServer(server));
}
assertEquals(newgroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tb1).getName());
assertTrue(newgroup.containsTable(tb1));
assertEquals(normal.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tb2).getName());
}
}

View File

@ -292,6 +292,8 @@ public abstract class TestRSGroupsBase {
boolean postRemoveServersCalled = false;
boolean preMoveServersAndTables = false;
boolean postMoveServersAndTables = false;
boolean preReNameRSGroupCalled = false;
boolean postReNameRSGroupCalled = false;
public void resetFlags() {
preBalanceRSGroupCalled = false;
@ -308,6 +310,8 @@ public abstract class TestRSGroupsBase {
postRemoveServersCalled = false;
preMoveServersAndTables = false;
postMoveServersAndTables = false;
preReNameRSGroupCalled = false;
postReNameRSGroupCalled = false;
}
@Override
@ -395,5 +399,17 @@ public abstract class TestRSGroupsBase {
String groupName, boolean balancerRan) throws IOException {
postBalanceRSGroupCalled = true;
}
@Override
public void preRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
preReNameRSGroupCalled = true;
}
@Override
public void postRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
postReNameRSGroupCalled = true;
}
}
}

View File

@ -110,6 +110,12 @@ public class VerifyingRSGroupAdminClient implements RSGroupAdmin {
verify();
}
@Override
public void renameRSGroup(String oldName, String newName) throws IOException {
wrapped.renameRSGroup(oldName, newName);
verify();
}
public void verify() throws IOException {
Map<String, RSGroupInfo> groupMap = Maps.newHashMap();
Set<RSGroupInfo> zList = Sets.newHashSet();

View File

@ -685,4 +685,15 @@ public class BaseMasterAndRegionObserver extends BaseRegionObserver
public void postRemoveServers(ObserverContext<MasterCoprocessorEnvironment> ctx,
Set<Address> servers) throws IOException {
}
@Override
public void preRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
@Override
public void postRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
}

View File

@ -685,4 +685,14 @@ public class BaseMasterObserver implements MasterObserver {
public void postBalanceRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String groupName, boolean balancerRan) throws IOException {
}
@Override
public void preRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
@Override
public void postRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
}

View File

@ -1215,4 +1215,25 @@ public interface MasterObserver extends Coprocessor {
*/
void postBalanceRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
String groupName, boolean balancerRan) throws IOException;
/**
* Called before rename rsgroup.
* @param ctx the environment to interact with the framework and master
* @param oldName old rsgroup name
* @param newName new rsgroup name
* @throws IOException on failure
*/
void preRenameRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final String oldName, final String newName) throws IOException;
/**
* Called after rename rsgroup.
* @param ctx the environment to interact with the framework and master
* @param oldName old rsgroup name
* @param newName new rsgroup name
* @throws IOException on failure
*/
void postRenameRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final String oldName, final String newName) throws IOException;
}

View File

@ -1435,6 +1435,32 @@ public class MasterCoprocessorHost
});
}
public void preRenameRSGroup(final String oldName, final String newName)
throws IOException {
execOperation(coprocessors.isEmpty() ? null: new CoprocessorOperation() {
@Override
public void call(MasterObserver oserver,
ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
if(((MasterEnvironment)ctx.getEnvironment()).supportGroupCPs) {
oserver.preRenameRSGroup(ctx, oldName, newName);
}
}
});
}
public void postRenameRSGroup(final String oldName, final String newName)
throws IOException {
execOperation(coprocessors.isEmpty() ? null: new CoprocessorOperation() {
@Override
public void call(MasterObserver oserver,
ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
if(((MasterEnvironment)ctx.getEnvironment()).supportGroupCPs) {
oserver.postRenameRSGroup(ctx, oldName, newName);
}
}
});
}
private static abstract class CoprocessorOperation
extends ObserverContext<MasterCoprocessorEnvironment> {
public CoprocessorOperation() {

View File

@ -1367,6 +1367,15 @@ public class TestMasterObserver {
String groupName, boolean balancerRan) throws IOException {
}
@Override
public void preRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
@Override
public void postRenameRSGroup(ObserverContext<MasterCoprocessorEnvironment> ctx,
String oldName, String newName) throws IOException {
}
}
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();