HBASE-8170 HbaseAdmin.createTable cannot handle creating three regions(jmspaggi)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1459875 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
708669b53f
commit
d372221802
|
@ -376,6 +376,10 @@ public class HBaseAdmin implements Abortable, Closeable {
|
|||
} else if(Bytes.compareTo(startKey, endKey) >= 0) {
|
||||
throw new IllegalArgumentException("Start key must be smaller than end key");
|
||||
}
|
||||
if (numRegions == 3) {
|
||||
createTable(desc, new byte[][]{startKey, endKey});
|
||||
return;
|
||||
}
|
||||
byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3);
|
||||
if(splitKeys == null || splitKeys.length != numRegions - 1) {
|
||||
throw new IllegalArgumentException("Unable to split key range into enough regions");
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.commons.logging.impl.Log4JLogger;
|
|||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.*;
|
||||
import org.apache.hadoop.hbase.catalog.CatalogTracker;
|
||||
import org.apache.hadoop.hbase.client.HTable;
|
||||
import org.apache.hadoop.hbase.exceptions.InvalidFamilyOperationException;
|
||||
import org.apache.hadoop.hbase.exceptions.MasterNotRunningException;
|
||||
import org.apache.hadoop.hbase.exceptions.NotServingRegionException;
|
||||
|
@ -544,6 +545,55 @@ public class TestAdmin {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableNumberOfRegions() throws IOException, InterruptedException {
|
||||
byte[] tableName = Bytes.toBytes("testCreateTableNumberOfRegions");
|
||||
HTableDescriptor desc = new HTableDescriptor(tableName);
|
||||
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
|
||||
admin.createTable(desc);
|
||||
HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||
Map<HRegionInfo, ServerName> regions = ht.getRegionLocations();
|
||||
assertEquals("Table should have only 1 region", 1, regions.size());
|
||||
ht.close();
|
||||
|
||||
byte [] TABLE_2 = Bytes.add(tableName, Bytes.toBytes("_2"));
|
||||
desc = new HTableDescriptor(TABLE_2);
|
||||
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
|
||||
admin.createTable(desc, new byte[][]{new byte[]{42}});
|
||||
HTable ht2 = new HTable(TEST_UTIL.getConfiguration(), TABLE_2);
|
||||
regions = ht2.getRegionLocations();
|
||||
assertEquals("Table should have only 2 region", 2, regions.size());
|
||||
ht2.close();
|
||||
|
||||
byte [] TABLE_3 = Bytes.add(tableName, Bytes.toBytes("_3"));
|
||||
desc = new HTableDescriptor(TABLE_3);
|
||||
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
|
||||
admin.createTable(desc, "a".getBytes(), "z".getBytes(), 3);
|
||||
HTable ht3 = new HTable(TEST_UTIL.getConfiguration(), TABLE_3);
|
||||
regions = ht3.getRegionLocations();
|
||||
assertEquals("Table should have only 3 region", 3, regions.size());
|
||||
ht3.close();
|
||||
|
||||
byte [] TABLE_4 = Bytes.add(tableName, Bytes.toBytes("_4"));
|
||||
desc = new HTableDescriptor(TABLE_4);
|
||||
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
|
||||
try {
|
||||
admin.createTable(desc, "a".getBytes(), "z".getBytes(), 2);
|
||||
fail("Should not be able to create a table with only 2 regions using this API.");
|
||||
} catch (IllegalArgumentException eae) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
byte [] TABLE_5 = Bytes.add(tableName, Bytes.toBytes("_5"));
|
||||
desc = new HTableDescriptor(TABLE_5);
|
||||
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
|
||||
admin.createTable(desc, new byte[] {1}, new byte[] {127}, 16);
|
||||
HTable ht5 = new HTable(TEST_UTIL.getConfiguration(), TABLE_5);
|
||||
regions = ht5.getRegionLocations();
|
||||
assertEquals("Table should have 16 region", 16, regions.size());
|
||||
ht5.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTableWithRegions() throws IOException, InterruptedException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue