[
https://issues.apache.org/jira/browse/HBASE-8170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13609373#comment-13609373
]
Jean-Marc Spaggiari commented on HBASE-8170:
--------------------------------------------
The method you are calling is using the Bytes.split function to split the keys
and then is calling HBaseAdmin.createTable(final HTableDescriptor desc, byte
[][] splitKeys)
In this method you can see this in the documentation: The total number of
regions created will be the number of split keys plus one.
Which mean that each key you are passing is defining the end or/and the
beginning of a region, without any overlap.
As an example:
{code}
byte[] a = "a".getBytes();
byte[] b = "z".getBytes();
byte[][] splits = Bytes.split(a, b, 1);
{code}
Will give you 3 splits. "a", "m" and "z".
If you give that to createTable, that will give you 4 regions. Something like
#00 to "a", "a" to "m", "m" to "z" and finally "z" to #ff. (but without the
overlaps).
So if you want to have only 3 regions, you need to call split (a, b, 0). Which
is why it's calling it with numRegions - 3.
But Bytes.split is not working with 0. So we have 2 options here.
1) We change (numRegions < 3) by (numRegions < 4) to force at least 4 regions.
That way split is called with at least 1.
2) We implement a special scenario when numRegions = 3 and use the 2 keys
Something like that:
{code}
public void createTable(HTableDescriptor desc, byte [] startKey,
byte [] endKey, int numRegions)
throws IOException {
HTableDescriptor.isLegalTableName(desc.getName());
if(numRegions < 3) {
throw new IllegalArgumentException("Must create at least three regions");
} 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");
}
createTable(desc, splitKeys);
}
{code}
> HbaseAdmin.createTable cannot handle creating three regions
> -----------------------------------------------------------
>
> Key: HBASE-8170
> URL: https://issues.apache.org/jira/browse/HBASE-8170
> Project: HBase
> Issue Type: Bug
> Components: Admin
> Affects Versions: 0.94.5
> Reporter: Edward C. Skoviak
> Priority: Minor
>
> createTable(HTableDescriptor desc, byte [] startKey, byte [] endKey, int
> numRegions) (line #370) dictates that you must specify a minimum of three
> regions, however is not able to handle being fed a value three. This is a
> result of line #379 where it attempts to create the key splits, and calls
> Bytes.Split with a value of 0 for the third parameter. createTable should
> instead just create a byte[][] with the startKey and endKey in this scenario.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira