You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by an...@apache.org on 2013/03/26 17:46:29 UTC
svn commit: r1461223 - 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: anoopsamjohn
Date: Tue Mar 26 16:46:29 2013
New Revision: 1461223
URL: http://svn.apache.org/r1461223
Log:
HBASE-8170 HbaseAdmin.createTable cannot handle creating three regions(jmspaggi)
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=1461223&r1=1461222&r2=1461223&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 Mar 26 16:46:29 2013
@@ -381,6 +381,10 @@ public class HBaseAdmin implements Abort
} 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");
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=1461223&r1=1461222&r2=1461223&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 Mar 26 16:46:29 2013
@@ -548,6 +548,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 {
byte[] tableName = Bytes.toBytes("testCreateTableWithRegions");