Skip to content
Merged
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 @@ -98,4 +98,11 @@ void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
* @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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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 org.apache.yetus.audience.InterfaceAudience;

Expand Down Expand Up @@ -236,4 +237,16 @@ public void removeServers(Set<Address> servers) throws IOException {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
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;
Expand Down Expand Up @@ -441,6 +443,30 @@ public void removeServers(RpcController controller,
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,13 @@ public void removeServers(Set<Address> servers) throws IOException {
}
}

@Override
public void renameRSGroup(String oldName, String newName) throws IOException {
synchronized (rsGroupInfoManager) {
rsGroupInfoManager.renameRSGroup(oldName, newName);
}
}

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 @@ -125,4 +125,11 @@ void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
* @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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,23 @@ public synchronized void removeServers(Set<Address> servers) throws IOException
}
}

@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> rsGroupInfoList = Lists.newArrayList();
try (Table table = conn.getTable(RSGROUP_TABLE_NAME);
Expand Down
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 @@ -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);
Expand Down Expand Up @@ -156,4 +164,7 @@ service RSGroupAdminService {

rpc RemoveServers(RemoveServersRequest)
returns (RemoveServersResponse);

rpc RenameRSGroup(RenameRSGroupRequest)
returns (RenameRSGroupResponse);
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,47 @@ private void toggleQuotaCheckAndRestartMiniCluster(boolean enable) throws Except
TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true);
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ public static class CPMasterObserver implements MasterCoprocessor, MasterObserve
boolean postRemoveServersCalled = false;
boolean preMoveServersAndTables = false;
boolean postMoveServersAndTables = false;
boolean preReNameRSGroupCalled = false;
boolean postReNameRSGroupCalled = false;

public void resetFlags() {
preBalanceRSGroupCalled = false;
Expand All @@ -320,6 +322,8 @@ public void resetFlags() {
postRemoveServersCalled = false;
preMoveServersAndTables = false;
postMoveServersAndTables = false;
preReNameRSGroupCalled = false;
postReNameRSGroupCalled = false;
}

@Override
Expand Down Expand Up @@ -412,6 +416,18 @@ public void postBalanceRSGroup(final ObserverContext<MasterCoprocessorEnvironmen
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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public void removeServers(Set<Address> servers) throws IOException {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,4 +1624,26 @@ default void preHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment>
default void postHasUserPermissions(ObserverContext<MasterCoprocessorEnvironment> ctx,
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 {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,26 @@ public void call(MasterObserver observer) throws IOException {
});
}

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)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
Expand Down