You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ra...@apache.org on 2012/04/24 18:20:58 UTC

svn commit: r1329827 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java test/java/org/apache/hadoop/hbase/client/TestAdmin.java

Author: ramkrishna
Date: Tue Apr 24 16:20:58 2012
New Revision: 1329827

URL: http://svn.apache.org/viewvc?rev=1329827&view=rev
Log:
HBASE-5848 Create table with EMPTY_START_ROW passed as splitKey causes the HMaster to abort (Ram)

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1329827&r1=1329826&r2=1329827&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Tue Apr 24 16:20:58 2012
@@ -374,11 +374,13 @@ public class HBaseAdmin implements Abort
    * Creates a new table with an initial set of empty regions defined by the
    * specified split keys.  The total number of regions created will be the
    * number of split keys plus one. Synchronous operation.
+   * Note : Avoid passing empty split key.
    *
    * @param desc table descriptor for table
    * @param splitKeys array of split keys for the initial regions of the table
    *
-   * @throws IllegalArgumentException if the table name is reserved
+   * @throws IllegalArgumentException if the table name is reserved, if the split keys
+   * are repeated and if the split key has empty byte array.
    * @throws MasterNotRunningException if master is not running
    * @throws TableExistsException if table already exists (If concurrent
    * threads, the table may have been created between test-for-existence
@@ -453,10 +455,11 @@ public class HBaseAdmin implements Abort
    * Asynchronous operation.  To check if the table exists, use
    * {@link: #isTableAvailable} -- it is not safe to create an HTable
    * instance to this table before it is available.
-   *
+   * Note : Avoid passing empty split key.
    * @param desc table descriptor for table
    *
-   * @throws IllegalArgumentException Bad table name.
+   * @throws IllegalArgumentException Bad table name, if the split keys
+   * are repeated and if the split key has empty byte array.
    * @throws MasterNotRunningException if master is not running
    * @throws TableExistsException if table already exists (If concurrent
    * threads, the table may have been created between test-for-existence
@@ -466,11 +469,15 @@ public class HBaseAdmin implements Abort
   public void createTableAsync(HTableDescriptor desc, byte [][] splitKeys)
   throws IOException {
     HTableDescriptor.isLegalTableName(desc.getName());
-    if(splitKeys != null && splitKeys.length > 1) {
+    if(splitKeys != null && splitKeys.length > 0) {
       Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR);
       // Verify there are no duplicate split keys
       byte [] lastKey = null;
       for(byte [] splitKey : splitKeys) {
+        if (Bytes.compareTo(splitKey, HConstants.EMPTY_BYTE_ARRAY) == 0) {
+          throw new IllegalArgumentException(
+              "Empty split key must not be passed in the split keys.");
+        }
         if(lastKey != null && Bytes.equals(splitKey, lastKey)) {
           throw new IllegalArgumentException("All split keys must be unique, " +
             "found duplicate: " + Bytes.toStringBinary(splitKey) +

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1329827&r1=1329826&r2=1329827&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Tue Apr 24 16:20:58 2012
@@ -713,6 +713,38 @@ public class TestAdmin {
     }
     ladmin.close();
   }
+  
+    
+  @Test
+  public void testCreateTableWithOnlyEmptyStartRow() throws IOException {
+    byte[] tableName = Bytes.toBytes("testCreateTableWithOnlyEmptyStartRow");
+    byte[][] splitKeys = new byte[1][];
+    splitKeys[0] = HConstants.EMPTY_BYTE_ARRAY;
+    HTableDescriptor desc = new HTableDescriptor(tableName);
+    desc.addFamily(new HColumnDescriptor("col"));
+    try {
+      admin.createTable(desc, splitKeys);
+      fail("Test case should fail as empty split key is passed.");
+    } catch (IllegalArgumentException e) {
+    }
+  }
+    
+  @Test
+  public void testCreateTableWithEmptyRowInTheSplitKeys() throws IOException {
+    byte[] tableName = Bytes
+        .toBytes("testCreateTableWithEmptyRowInTheSplitKeys");
+    byte[][] splitKeys = new byte[3][];
+    splitKeys[0] = "region1".getBytes();
+    splitKeys[1] = HConstants.EMPTY_BYTE_ARRAY;
+    splitKeys[2] = "region2".getBytes();
+    HTableDescriptor desc = new HTableDescriptor(tableName);
+    desc.addFamily(new HColumnDescriptor("col"));
+    try {
+      admin.createTable(desc, splitKeys);
+      fail("Test case should fail as empty split key is passed.");
+    } catch (IllegalArgumentException e) {
+    }
+  }
 
   @Test
   public void testTableExist() throws IOException {