HBASE-24112 [RSGroup] Support renaming rsgroup (#1520)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
2d27e8d2d5
commit
28e729510d
|
@ -98,4 +98,11 @@ public interface RSGroupAdmin {
|
||||||
* @param servers set of servers to remove
|
* @param servers set of servers to remove
|
||||||
*/
|
*/
|
||||||
void removeServers(Set<Address> servers) throws IOException;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,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.RSGroupAdminService;
|
||||||
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveRSGroupRequest;
|
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.RemoveServersRequest;
|
||||||
|
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RenameRSGroupRequest;
|
||||||
import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos;
|
import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
|
|
||||||
|
@ -236,4 +237,16 @@ public class RSGroupAdminClient implements RSGroupAdmin {
|
||||||
throw ProtobufUtil.handleRemoteException(e);
|
throw ProtobufUtil.handleRemoteException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,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.RemoveRSGroupResponse;
|
||||||
import org.apache.hadoop.hbase.protobuf.generated.RSGroupAdminProtos.RemoveServersRequest;
|
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.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.protobuf.generated.TableProtos;
|
||||||
import org.apache.hadoop.hbase.security.User;
|
import org.apache.hadoop.hbase.security.User;
|
||||||
import org.apache.hadoop.hbase.security.UserProvider;
|
import org.apache.hadoop.hbase.security.UserProvider;
|
||||||
|
@ -441,6 +443,30 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver {
|
||||||
}
|
}
|
||||||
done.run(builder.build());
|
done.run(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameRSGroup(RpcController controller,
|
||||||
|
RenameRSGroupRequest request,
|
||||||
|
RpcCallback<RenameRSGroupResponse> done) {
|
||||||
|
String oldRSGroup = request.getOldRsgroupName();
|
||||||
|
String newRSGroup = request.getNewRsgroupName();
|
||||||
|
LOG.info("{} rename rsgroup from {} to {}",
|
||||||
|
master.getClientIdAuditPrefix(), oldRSGroup, newRSGroup);
|
||||||
|
|
||||||
|
RenameRSGroupResponse.Builder builder = RenameRSGroupResponse.newBuilder();
|
||||||
|
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) {
|
||||||
|
CoprocessorRpcUtils.setControllerException(controller, e);
|
||||||
|
}
|
||||||
|
done.run(builder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean rsgroupHasServersOnline(TableDescriptor desc) throws IOException {
|
boolean rsgroupHasServersOnline(TableDescriptor desc) throws IOException {
|
||||||
|
|
|
@ -525,6 +525,13 @@ public class RSGroupAdminServer implements RSGroupAdmin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameRSGroup(String oldName, String newName) throws IOException {
|
||||||
|
synchronized (rsGroupInfoManager) {
|
||||||
|
rsGroupInfoManager.renameRSGroup(oldName, newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName)
|
private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Map<String, RegionState> rit = Maps.newTreeMap();
|
Map<String, RegionState> rit = Maps.newTreeMap();
|
||||||
|
|
|
@ -125,4 +125,11 @@ public interface RSGroupInfoManager {
|
||||||
* @param servers set of servers to remove
|
* @param servers set of servers to remove
|
||||||
*/
|
*/
|
||||||
void removeServers(Set<Address> servers) throws IOException;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,6 +349,23 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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,
|
||||||
|
(SortedSet<Address>) oldGroup.getServers(), oldGroup.getTables());
|
||||||
|
newGroupMap.put(newName, newGroup);
|
||||||
|
flushConfig(newGroupMap);
|
||||||
|
}
|
||||||
|
|
||||||
List<RSGroupInfo> retrieveGroupListFromGroupTable() throws IOException {
|
List<RSGroupInfo> retrieveGroupListFromGroupTable() throws IOException {
|
||||||
List<RSGroupInfo> rsGroupInfoList = Lists.newArrayList();
|
List<RSGroupInfo> rsGroupInfoList = Lists.newArrayList();
|
||||||
try (Table table = conn.getTable(RSGROUP_TABLE_NAME);
|
try (Table table = conn.getTable(RSGROUP_TABLE_NAME);
|
||||||
|
|
|
@ -123,6 +123,14 @@ message RemoveServersRequest {
|
||||||
message RemoveServersResponse {
|
message RemoveServersResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message RenameRSGroupRequest {
|
||||||
|
required string old_rsgroup_name = 1;
|
||||||
|
required string new_rsgroup_name = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RenameRSGroupResponse {
|
||||||
|
}
|
||||||
|
|
||||||
service RSGroupAdminService {
|
service RSGroupAdminService {
|
||||||
rpc GetRSGroupInfo(GetRSGroupInfoRequest)
|
rpc GetRSGroupInfo(GetRSGroupInfoRequest)
|
||||||
returns (GetRSGroupInfoResponse);
|
returns (GetRSGroupInfoResponse);
|
||||||
|
@ -156,4 +164,7 @@ service RSGroupAdminService {
|
||||||
|
|
||||||
rpc RemoveServers(RemoveServersRequest)
|
rpc RemoveServers(RemoveServersRequest)
|
||||||
returns (RemoveServersResponse);
|
returns (RemoveServersResponse);
|
||||||
|
|
||||||
|
rpc RenameRSGroup(RenameRSGroupRequest)
|
||||||
|
returns (RenameRSGroupResponse);
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,4 +497,47 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
|
||||||
TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
|
TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRenameRSGroup() throws Exception {
|
||||||
|
// Add rsgroup, and assign 2 servers and a table to it.
|
||||||
|
RSGroupInfo oldgroup = addGroup("oldgroup", 2);
|
||||||
|
final TableName tb1 = TableName.valueOf("testRename");
|
||||||
|
TEST_UTIL.createTable(tb1, "tr");
|
||||||
|
rsGroupAdmin.moveTables(Sets.newHashSet(tb1), oldgroup.getName());
|
||||||
|
TEST_UTIL.waitFor(1000,
|
||||||
|
(Waiter.Predicate<Exception>) () ->
|
||||||
|
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("normal", 1);
|
||||||
|
final TableName tb2 = TableName.valueOf("unmovedTable");
|
||||||
|
TEST_UTIL.createTable(tb2, "ut");
|
||||||
|
rsGroupAdmin.moveTables(Sets.newHashSet(tb2), normal.getName());
|
||||||
|
TEST_UTIL.waitFor(1000,
|
||||||
|
(Waiter.Predicate<Exception>) () ->
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,6 +304,8 @@ public abstract class TestRSGroupsBase {
|
||||||
boolean postRemoveServersCalled = false;
|
boolean postRemoveServersCalled = false;
|
||||||
boolean preMoveServersAndTables = false;
|
boolean preMoveServersAndTables = false;
|
||||||
boolean postMoveServersAndTables = false;
|
boolean postMoveServersAndTables = false;
|
||||||
|
boolean preReNameRSGroupCalled = false;
|
||||||
|
boolean postReNameRSGroupCalled = false;
|
||||||
|
|
||||||
public void resetFlags() {
|
public void resetFlags() {
|
||||||
preBalanceRSGroupCalled = false;
|
preBalanceRSGroupCalled = false;
|
||||||
|
@ -320,6 +322,8 @@ public abstract class TestRSGroupsBase {
|
||||||
postRemoveServersCalled = false;
|
postRemoveServersCalled = false;
|
||||||
preMoveServersAndTables = false;
|
preMoveServersAndTables = false;
|
||||||
postMoveServersAndTables = false;
|
postMoveServersAndTables = false;
|
||||||
|
preReNameRSGroupCalled = false;
|
||||||
|
postReNameRSGroupCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -412,6 +416,18 @@ public abstract class TestRSGroupsBase {
|
||||||
String groupName, boolean balancerRan) throws IOException {
|
String groupName, boolean balancerRan) throws IOException {
|
||||||
postBalanceRSGroupCalled = true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,12 @@ public class VerifyingRSGroupAdminClient implements RSGroupAdmin {
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renameRSGroup(String oldName, String newName) throws IOException {
|
||||||
|
wrapped.renameRSGroup(oldName, newName);
|
||||||
|
verify();
|
||||||
|
}
|
||||||
|
|
||||||
public void verify() throws IOException {
|
public void verify() throws IOException {
|
||||||
Map<String, RSGroupInfo> groupMap = Maps.newHashMap();
|
Map<String, RSGroupInfo> groupMap = Maps.newHashMap();
|
||||||
Set<RSGroupInfo> zList = Sets.newHashSet();
|
Set<RSGroupInfo> zList = Sets.newHashSet();
|
||||||
|
|
|
@ -1624,4 +1624,26 @@ public interface MasterObserver {
|
||||||
default void postHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
|
default void postHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
|
||||||
String userName, List<Permission> permissions) throws IOException {
|
String userName, List<Permission> permissions) 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
|
||||||
|
*/
|
||||||
|
default 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
|
||||||
|
*/
|
||||||
|
default void postRenameRSGroup(final ObserverContext<MasterCoprocessorEnvironment> ctx,
|
||||||
|
final String oldName, final String newName) throws IOException {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1453,6 +1453,26 @@ public class MasterCoprocessorHost
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void preRenameRSGroup(final String oldName, final String newName)
|
||||||
|
throws IOException {
|
||||||
|
execOperation(coprocEnvironments.isEmpty() ? null: new MasterObserverOperation() {
|
||||||
|
@Override
|
||||||
|
public void call(MasterObserver observer) throws IOException {
|
||||||
|
observer.preRenameRSGroup(this, oldName, newName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postRenameRSGroup(final String oldName, final String newName)
|
||||||
|
throws IOException {
|
||||||
|
execOperation(coprocEnvironments.isEmpty() ? null: new MasterObserverOperation() {
|
||||||
|
@Override
|
||||||
|
public void call(MasterObserver observer) throws IOException {
|
||||||
|
observer.postRenameRSGroup(this, oldName, newName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void preRemoveServers(final Set<Address> servers)
|
public void preRemoveServers(final Set<Address> servers)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
|
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
|
||||||
|
|
Loading…
Reference in New Issue