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:14:22 UTC
svn commit: r1329819 - in /hbase/trunk/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:14:22 2012
New Revision: 1329819
URL: http://svn.apache.org/viewvc?rev=1329819&view=rev
Log:
HBASE-5848 Create table with EMPTY_START_ROW passed as splitKey causes the HMaster to abort (Ram)
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1329819&r1=1329818&r2=1329819&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Tue Apr 24 16:14:22 2012
@@ -367,11 +367,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
@@ -446,10 +448,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
@@ -460,11 +463,15 @@ public class HBaseAdmin implements Abort
final HTableDescriptor desc, final 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/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1329819&r1=1329818&r2=1329819&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Tue Apr 24 16:14:22 2012
@@ -715,6 +715,36 @@ 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 {