HBASE-20220 [RSGroup] Check if table exists in the cluster before moving it to the specified regionserver group

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Guangxu Cheng 2018-03-20 00:56:41 +08:00 committed by tedyu
parent df5de33a02
commit 45586ab300
3 changed files with 46 additions and 2 deletions

View File

@ -25,6 +25,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.net.Address; import org.apache.hadoop.hbase.net.Address;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
@ -55,9 +57,11 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
@InterfaceAudience.Private @InterfaceAudience.Private
class RSGroupAdminClient implements RSGroupAdmin { class RSGroupAdminClient implements RSGroupAdmin {
private RSGroupAdminService.BlockingInterface stub; private RSGroupAdminService.BlockingInterface stub;
private Admin admin;
public RSGroupAdminClient(Connection conn) throws IOException { public RSGroupAdminClient(Connection conn) throws IOException {
stub = RSGroupAdminService.newBlockingStub(conn.getAdmin().coprocessorService()); admin = conn.getAdmin();
stub = RSGroupAdminService.newBlockingStub(admin.coprocessorService());
} }
@Override @Override
@ -114,6 +118,9 @@ class RSGroupAdminClient implements RSGroupAdmin {
MoveTablesRequest.Builder builder = MoveTablesRequest.newBuilder().setTargetGroup(targetGroup); MoveTablesRequest.Builder builder = MoveTablesRequest.newBuilder().setTargetGroup(targetGroup);
for(TableName tableName: tables) { for(TableName tableName: tables) {
builder.addTableName(ProtobufUtil.toProtoTableName(tableName)); builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
if (!admin.tableExists(tableName)) {
throw new TableNotFoundException(tableName);
}
} }
try { try {
stub.moveTables(null, builder.build()); stub.moveTables(null, builder.build());
@ -200,6 +207,9 @@ class RSGroupAdminClient implements RSGroupAdmin {
} }
for(TableName tableName: tables) { for(TableName tableName: tables) {
builder.addTableName(ProtobufUtil.toProtoTableName(tableName)); builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
if (!admin.tableExists(tableName)) {
throw new TableNotFoundException(tableName);
}
} }
try { try {
stub.moveServersAndTables(null, builder.build()); stub.moveServersAndTables(null, builder.build());

View File

@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.RegionMetrics;
import org.apache.hadoop.hbase.ServerMetrics; import org.apache.hadoop.hbase.ServerMetrics;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.client.ClusterConnection;
@ -208,7 +209,7 @@ public abstract class TestRSGroupsBase {
try { try {
rsGroupAdmin.moveTables(Sets.newHashSet(TableName.valueOf("bogustable")), "bogus"); rsGroupAdmin.moveTables(Sets.newHashSet(TableName.valueOf("bogustable")), "bogus");
fail("Expected move with bogus group to fail"); fail("Expected move with bogus group to fail");
} catch(ConstraintException ex) { } catch(ConstraintException|TableNotFoundException ex) {
//expected //expected
} }
@ -761,6 +762,37 @@ public abstract class TestRSGroupsBase {
rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName()); rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName());
} }
@Test
public void testNonExistentTableMove() throws Exception {
TableName tableName = TableName.valueOf(tablePrefix + name.getMethodName());
RSGroupInfo tableGrp = rsGroupAdmin.getRSGroupInfoOfTable(tableName);
assertNull(tableGrp);
//test if table exists already.
boolean exist = admin.tableExists(tableName);
assertFalse(exist);
LOG.info("Moving table "+ tableName + " to " + RSGroupInfo.DEFAULT_GROUP);
try {
rsGroupAdmin.moveTables(Sets.newHashSet(tableName), RSGroupInfo.DEFAULT_GROUP);
fail("Table " + tableName + " shouldn't have been successfully moved.");
} catch(IOException ex) {
assertTrue(ex instanceof TableNotFoundException);
}
try {
rsGroupAdmin.moveServersAndTables(
Sets.newHashSet(Address.fromParts("bogus",123)),
Sets.newHashSet(tableName), RSGroupInfo.DEFAULT_GROUP);
fail("Table " + tableName + " shouldn't have been successfully moved.");
} catch(IOException ex) {
assertTrue(ex instanceof TableNotFoundException);
}
//verify group change
assertNull(rsGroupAdmin.getRSGroupInfoOfTable(tableName));
}
@Test @Test
public void testMoveServersAndTables() throws Exception { public void testMoveServersAndTables() throws Exception {
LOG.info("testMoveServersAndTables"); LOG.info("testMoveServersAndTables");

View File

@ -112,6 +112,8 @@ module Shell
handle_exceptions(cause, *args) if respond_to?(:handle_exceptions) handle_exceptions(cause, *args) if respond_to?(:handle_exceptions)
# Global HBase exception handling below if not handled by respective command above # Global HBase exception handling below if not handled by respective command above
if cause.is_a?(org.apache.hadoop.hbase.TableNotFoundException) if cause.is_a?(org.apache.hadoop.hbase.TableNotFoundException)
strs = cause.to_s.split(' ')
raise "Unknown table #{strs[0]}!" if strs.size == 1
raise "Unknown table #{args.first}!" raise "Unknown table #{args.first}!"
end end
if cause.is_a?(org.apache.hadoop.hbase.UnknownRegionException) if cause.is_a?(org.apache.hadoop.hbase.UnknownRegionException)