hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject hbase git commit: HBASE-13812 Deleting of last Column Family of a table should not be allowed
Date Sat, 30 May 2015 23:31:12 GMT
Repository: hbase
Updated Branches:
  refs/heads/master ee30d050d -> ae803d72f


HBASE-13812 Deleting of last Column Family of a table should not be allowed


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

Branch: refs/heads/master
Commit: ae803d72fe3816378a9d2acd1775c01c9db19198
Parents: ee30d05
Author: Enis Soztutar <enis@apache.org>
Authored: Sat May 30 16:30:48 2015 -0700
Committer: Enis Soztutar <enis@apache.org>
Committed: Sat May 30 16:30:48 2015 -0700

----------------------------------------------------------------------
 .../procedure/DeleteColumnFamilyProcedure.java  |  5 +++
 .../apache/hadoop/hbase/client/TestAdmin1.java  | 35 +++++++++++++++++---
 2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ae803d72/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
index 0a64c71..6e52ec2 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteColumnFamilyProcedure.java
@@ -284,6 +284,11 @@ public class DeleteColumnFamilyProcedure
       throw new InvalidFamilyOperationException("Family '" + getColumnFamilyName()
           + "' does not exist, so it cannot be deleted");
     }
+
+    if (unmodifiedHTableDescriptor.getColumnFamilies().length == 1) {
+      throw new InvalidFamilyOperationException("Family '" + getColumnFamilyName()
+        + "' is the only column family in the table, so it cannot be deleted");
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/ae803d72/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
index bd6d2bb..02bc3c7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java
@@ -60,7 +60,6 @@ import org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -1279,10 +1278,9 @@ public class TestAdmin1 {
 
   @Test (timeout=300000)
   public void testEnableDisableAddColumnDeleteColumn() throws Exception {
-    ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
-    TableName tableName = TableName.valueOf("testMasterAdmin");
+    TableName tableName = TableName.valueOf("testEnableDisableAddColumnDeleteColumn");
     TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close();
-    while (!this.admin.isTableEnabled(TableName.valueOf("testMasterAdmin"))) {
+    while (!this.admin.isTableEnabled(TableName.valueOf("testEnableDisableAddColumnDeleteColumn")))
{
       Thread.sleep(10);
     }
     this.admin.disableTable(tableName);
@@ -1302,4 +1300,33 @@ public class TestAdmin1 {
     this.admin.disableTable(tableName);
     this.admin.deleteTable(tableName);
   }
+
+  @Test (timeout=300000)
+  public void testDeleteLastColumnFamily() throws Exception {
+    TableName tableName = TableName.valueOf("testDeleteLastColumnFamily");
+    TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close();
+    while (!this.admin.isTableEnabled(TableName.valueOf("testDeleteLastColumnFamily"))) {
+      Thread.sleep(10);
+    }
+
+    // test for enabled table
+    try {
+      this.admin.deleteColumnFamily(tableName, HConstants.CATALOG_FAMILY);
+      fail("Should have failed to delete the only column family of a table");
+    } catch (InvalidFamilyOperationException ex) {
+      // expected
+    }
+
+    // test for disabled table
+    this.admin.disableTable(tableName);
+
+    try {
+      this.admin.deleteColumnFamily(tableName, HConstants.CATALOG_FAMILY);
+      fail("Should have failed to delete the only column family of a table");
+    } catch (InvalidFamilyOperationException ex) {
+      // expected
+    }
+
+    this.admin.deleteTable(tableName);
+  }
 }


Mime
View raw message