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

Co-authored-by: wenbang <wenbang@didiglobal.com>
Signed-off-by: Reid Chan <reidchan@apache.org>
This commit is contained in:
wenbang 2020-05-29 11:39:42 +08:00 committed by GitHub
parent 7df034a824
commit 136414dd72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 3 deletions

View File

@ -23,7 +23,9 @@ 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.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceAudience;
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 com.google.protobuf.ServiceException;
@InterfaceAudience.Private @InterfaceAudience.Private
public class RSGroupAdminClient implements RSGroupAdmin { public 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 @@ public 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 @@ public 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

@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableExistsException;
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.constraint.ConstraintException; import org.apache.hadoop.hbase.constraint.ConstraintException;
import org.apache.hadoop.hbase.master.ServerManager; import org.apache.hadoop.hbase.master.ServerManager;
@ -118,7 +119,7 @@ public class TestRSGroupsAdmin1 extends 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
} }

View File

@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.rsgroup;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -37,6 +38,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
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.ClusterConnection; import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.HMaster;
@ -298,6 +300,37 @@ public class TestRSGroupsAdmin2 extends TestRSGroupsBase {
assertTrue(observer.preRemoveServersCalled); assertTrue(observer.preRemoveServersCalled);
} }
@Test
public void testNonExistentTableMove() throws Exception {
TableName tableName = TableName.valueOf(tablePrefix + rand.nextInt());
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 {
final TableName tableName = TableName.valueOf(tablePrefix + "_testMoveServersAndTables"); final TableName tableName = TableName.valueOf(tablePrefix + "_testMoveServersAndTables");
@ -414,4 +447,4 @@ public class TestRSGroupsAdmin2 extends TestRSGroupsBase {
assertTrue(observer.postMoveServersAndTables); assertTrue(observer.postMoveServersAndTables);
} }
} }

View File

@ -120,6 +120,8 @@ module Shell
end end
# 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.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then if cause.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then
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.kind_of?(org.apache.hadoop.hbase.UnknownRegionException) then if cause.kind_of?(org.apache.hadoop.hbase.UnknownRegionException) then