Repository: hbase
Updated Branches:
  refs/heads/branch-2 d1b511351 -> b5ae4e5f9


HBASE-20666 Unsuccessful table creation leaves entry in hbase:rsgroup table

Signed-off-by: tedyu <yuzhih...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b5ae4e5f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b5ae4e5f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b5ae4e5f

Branch: refs/heads/branch-2
Commit: b5ae4e5f9e6ecd52d9197bd49cd4cefad228e214
Parents: d1b5113
Author: Xu Cang <xc...@salesforce.com>
Authored: Mon Aug 20 01:14:27 2018 -0700
Committer: tedyu <yuzhih...@gmail.com>
Committed: Tue Aug 21 18:55:46 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/rsgroup/TestRSGroups.java      | 65 +++++++++++++++++++-
 .../master/procedure/CreateTableProcedure.java  |  6 ++
 2 files changed, 70 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/b5ae4e5f/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java
----------------------------------------------------------------------
diff --git 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java
index 5c2e64c..264c864 100644
--- 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java
+++ 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java
@@ -18,11 +18,13 @@
 package org.apache.hadoop.hbase.rsgroup;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Optional;
 import java.util.Set;
 
@@ -45,6 +47,7 @@ import org.apache.hadoop.hbase.coprocessor.MasterObserver;
 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
 import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
 import org.apache.hadoop.hbase.master.ServerManager;
+import org.apache.hadoop.hbase.master.TableNamespaceManager;
 import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
 import org.apache.hadoop.hbase.net.Address;
 import org.apache.hadoop.hbase.quotas.QuotaTableUtil;
@@ -94,7 +97,6 @@ public class TestRSGroups extends TestRSGroupsBase {
         ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,
         NUM_SLAVES_BASE - 1);
     
TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, 
true);
-
     initialize();
   }
 
@@ -456,6 +458,67 @@ public class TestRSGroups extends TestRSGroupsBase {
     }
   }
 
+  @Test
+  public void testRSGroupListDoesNotContainFailedTableCreation() throws 
Exception {
+    toggleQuotaCheckAndRestartMiniCluster(true);
+    String nsp = "np1";
+    NamespaceDescriptor nspDesc =
+        
NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS,
 "5")
+            .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, 
"2").build();
+    admin.createNamespace(nspDesc);
+    assertEquals(3, admin.listNamespaceDescriptors().length);
+    HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
+    HTableDescriptor tableDescOne =
+        new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM 
+ "table1"));
+    tableDescOne.addFamily(fam1);
+    admin.createTable(tableDescOne);
+
+    HTableDescriptor tableDescTwo =
+        new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM 
+ "table2"));
+    tableDescTwo.addFamily(fam1);
+    boolean constraintViolated = false;
+
+    try {
+      admin.createTable(tableDescTwo, Bytes.toBytes("AAA"), 
Bytes.toBytes("ZZZ"),
+          6);
+      Assert.fail("Creation table should fail because of quota violation.");
+    } catch (Exception exp) {
+      assertTrue(exp instanceof IOException);
+      constraintViolated = true;
+    } finally {
+      assertTrue("Constraint not violated for table " + 
tableDescTwo.getTableName(),
+          constraintViolated);
+    }
+    List<RSGroupInfo> rsGroupInfoList = rsGroupAdmin.listRSGroups();
+    boolean foundTable2 = false;
+    boolean foundTable1 = false;
+    for(int i = 0; i < rsGroupInfoList.size(); i++){
+      
if(rsGroupInfoList.get(i).getTables().contains(tableDescTwo.getTableName())){
+        foundTable2 = true;
+      }
+      
if(rsGroupInfoList.get(i).getTables().contains(tableDescOne.getTableName())){
+        foundTable1 = true;
+      }
+    }
+    assertFalse("Found table2 in rsgroup list.", foundTable2);
+    assertTrue("Did not find table1 in rsgroup list", foundTable1);
+
+    TEST_UTIL.deleteTable(tableDescOne.getTableName());
+    admin.deleteNamespace(nspDesc.getName());
+    toggleQuotaCheckAndRestartMiniCluster(false);
+
+  }
+  private void toggleQuotaCheckAndRestartMiniCluster(boolean enable) throws 
Exception{
+    TEST_UTIL.shutdownMiniCluster();
+    TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, enable);
+    TEST_UTIL.startMiniCluster(NUM_SLAVES_BASE - 1);
+    TEST_UTIL.getConfiguration().setInt(
+        ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART,
+        NUM_SLAVES_BASE - 1);
+    
TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, 
true);
+    initialize();
+  }
+
   private void restartHBaseCluster() throws Exception {
     LOG.info("\n\nShutting down cluster");
     TEST_UTIL.shutdownMiniHBaseCluster();

http://git-wip-us.apache.org/repos/asf/hbase/blob/b5ae4e5f/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
index faad3dd..449b0b4 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/CreateTableProcedure.java
@@ -140,6 +140,12 @@ public class CreateTableProcedure
       // We can fail if the table does exist or the descriptor is malformed.
       // TODO: coprocessor rollback semantic is still undefined.
       DeleteTableProcedure.deleteTableStates(env, getTableName());
+
+      final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
+      if (cpHost != null) {
+        cpHost.postDeleteTable(getTableName());
+      }
+
       releaseSyncLatch();
       return;
     }

Reply via email to