This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new fb91f64  HBASE-20220 [RSGroup] Check if table exists in the cluster 
before moving it to the specified regionserver group
fb91f64 is described below

commit fb91f64a04601d87b3e435a226f47ea6351a9bf2
Author: Guangxu Cheng <guangxuch...@gmail.com>
AuthorDate: Tue Mar 20 00:56:41 2018 +0800

    HBASE-20220 [RSGroup] Check if table exists in the cluster before moving it 
to the specified regionserver group
    
    Signed-off-by: tedyu <yuzhih...@gmail.com>
---
 .../hadoop/hbase/rsgroup/RSGroupAdminClient.java   | 12 ++++++++-
 .../hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java   | 31 ++++++++++++++++++++++
 .../hadoop/hbase/rsgroup/TestRSGroupsBase.java     |  2 --
 hbase-shell/src/main/ruby/shell/commands.rb        |  2 ++
 4 files changed, 44 insertions(+), 3 deletions(-)

diff --git 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java
 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java
index 380f323..eb9d915 100644
--- 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java
+++ 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java
@@ -25,6 +25,8 @@ import java.util.List;
 import java.util.Set;
 
 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.net.Address;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
@@ -55,9 +57,11 @@ import 
org.apache.hbase.thirdparty.com.google.common.collect.Sets;
 @InterfaceAudience.Private
 class RSGroupAdminClient implements RSGroupAdmin {
   private RSGroupAdminService.BlockingInterface stub;
+  private Admin admin;
 
   public RSGroupAdminClient(Connection conn) throws IOException {
-    stub = 
RSGroupAdminService.newBlockingStub(conn.getAdmin().coprocessorService());
+    admin = conn.getAdmin();
+    stub = RSGroupAdminService.newBlockingStub(admin.coprocessorService());
   }
 
   @Override
@@ -114,6 +118,9 @@ class RSGroupAdminClient implements RSGroupAdmin {
     MoveTablesRequest.Builder builder = 
MoveTablesRequest.newBuilder().setTargetGroup(targetGroup);
     for(TableName tableName: tables) {
       builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
+      if (!admin.tableExists(tableName)) {
+        throw new TableNotFoundException(tableName);
+      }
     }
     try {
       stub.moveTables(null, builder.build());
@@ -200,6 +207,9 @@ class RSGroupAdminClient implements RSGroupAdmin {
     }
     for(TableName tableName: tables) {
       builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
+      if (!admin.tableExists(tableName)) {
+        throw new TableNotFoundException(tableName);
+      }
     }
     try {
       stub.moveServersAndTables(null, builder.build());
diff --git 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java
 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java
index 5888afa..a4a3a7c 100644
--- 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java
+++ 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsAdmin1.java
@@ -377,6 +377,37 @@ public class TestRSGroupsAdmin1 extends TestRSGroupsBase {
   }
 
   @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
   public void testRSGroupListDoesNotContainFailedTableCreation() throws 
Exception {
     toggleQuotaCheckAndRestartMiniCluster(true);
     String nsp = "np1";
diff --git 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
index fdefe47..2d22087 100644
--- 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
+++ 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
@@ -29,7 +29,6 @@ import java.util.Optional;
 import java.util.Random;
 import java.util.Set;
 import java.util.TreeMap;
-
 import org.apache.hadoop.hbase.ClusterMetrics;
 import org.apache.hadoop.hbase.ClusterMetrics.Option;
 import org.apache.hadoop.hbase.HBaseCluster;
@@ -56,7 +55,6 @@ import org.apache.hadoop.hbase.master.ServerManager;
 import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
 import org.apache.hadoop.hbase.net.Address;
 import org.apache.hadoop.hbase.util.Bytes;
-
 import org.junit.Rule;
 import org.junit.rules.TestName;
 import org.slf4j.Logger;
diff --git a/hbase-shell/src/main/ruby/shell/commands.rb 
b/hbase-shell/src/main/ruby/shell/commands.rb
index d1b91f4..4fdc8b5 100644
--- a/hbase-shell/src/main/ruby/shell/commands.rb
+++ b/hbase-shell/src/main/ruby/shell/commands.rb
@@ -126,6 +126,8 @@ module Shell
         handle_exceptions(cause, *args) if respond_to?(:handle_exceptions)
         # Global HBase exception handling below if not handled by respective 
command above
         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}!"
         end
         if cause.is_a?(org.apache.hadoop.hbase.TableNotEnabledException)

Reply via email to