HBASE-5848 Create table with EMPTY_START_ROW passed as splitKey causes the HMaster to abort (Ram)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1329819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ramkrishna 2012-04-24 16:14:22 +00:00
parent 1ad0378006
commit 3644d4c8d6
2 changed files with 41 additions and 4 deletions

View File

@ -367,11 +367,13 @@ public class HBaseAdmin implements Abortable, Closeable {
* Creates a new table with an initial set of empty regions defined by the * 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 * specified split keys. The total number of regions created will be the
* number of split keys plus one. Synchronous operation. * number of split keys plus one. Synchronous operation.
* Note : Avoid passing empty split key.
* *
* @param desc table descriptor for table * @param desc table descriptor for table
* @param splitKeys array of split keys for the initial regions of the 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 MasterNotRunningException if master is not running
* @throws TableExistsException if table already exists (If concurrent * @throws TableExistsException if table already exists (If concurrent
* threads, the table may have been created between test-for-existence * threads, the table may have been created between test-for-existence
@ -446,10 +448,11 @@ public class HBaseAdmin implements Abortable, Closeable {
* Asynchronous operation. To check if the table exists, use * Asynchronous operation. To check if the table exists, use
* {@link: #isTableAvailable} -- it is not safe to create an HTable * {@link: #isTableAvailable} -- it is not safe to create an HTable
* instance to this table before it is available. * instance to this table before it is available.
* * Note : Avoid passing empty split key.
* @param desc table descriptor for table * @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 MasterNotRunningException if master is not running
* @throws TableExistsException if table already exists (If concurrent * @throws TableExistsException if table already exists (If concurrent
* threads, the table may have been created between test-for-existence * threads, the table may have been created between test-for-existence
@ -460,11 +463,15 @@ public class HBaseAdmin implements Abortable, Closeable {
final HTableDescriptor desc, final byte [][] splitKeys) final HTableDescriptor desc, final byte [][] splitKeys)
throws IOException { throws IOException {
HTableDescriptor.isLegalTableName(desc.getName()); HTableDescriptor.isLegalTableName(desc.getName());
if(splitKeys != null && splitKeys.length > 1) { if(splitKeys != null && splitKeys.length > 0) {
Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR); Arrays.sort(splitKeys, Bytes.BYTES_COMPARATOR);
// Verify there are no duplicate split keys // Verify there are no duplicate split keys
byte [] lastKey = null; byte [] lastKey = null;
for(byte [] splitKey : splitKeys) { 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)) { if(lastKey != null && Bytes.equals(splitKey, lastKey)) {
throw new IllegalArgumentException("All split keys must be unique, " + throw new IllegalArgumentException("All split keys must be unique, " +
"found duplicate: " + Bytes.toStringBinary(splitKey) + "found duplicate: " + Bytes.toStringBinary(splitKey) +

View File

@ -716,6 +716,36 @@ public class TestAdmin {
ladmin.close(); 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 @Test
public void testTableExist() throws IOException { public void testTableExist() throws IOException {
final byte [] table = Bytes.toBytes("testTableExist"); final byte [] table = Bytes.toBytes("testTableExist");