HBase fixed regions: Java
What's inside this article
⌄
- How to create HBase table with the specified number of regions in HBase Shell
- HBase constant number of regions
- HBase constant reginos
- HBase table fixed regions
- HBase fixed regions
Let’s say we need to create an HBase table with a certain constant number of regions.
Regions pre-creation
First, we need to create a table with a certain pre-created number of regions. We can use one of the createTable() method overloads for that:
void createTable(TableDescriptor desc, byte[][] splitKeys);
We can make the byte[][] splitKeys array as follows:
byte[][] splitKeys = new RegionSplitter.HexStringSplit().split(n);
We need to add the hbase-server module (for example, version 1.2.3) to pom.xml:
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.2.3</version>
</dependency>
WE can use another supported region split algorithm, for example, UniformSplit:
byte[][] splitKeys = new RegionSplitter.UniformSplit().split(n);
Disabling regions count autoincrease
For this purpose, we need to set RegionSplitPolicy through the TableDescriptor object, passed to the createTable() method:
HTableDescriptor htableDescr = new HTableDescriptor(tableName);
HColumnDescriptor hcolumnDescr = new HColumnDescriptor(COLUMN_FAMILY);
htableDescr.addFamily(hcolumnDescr);
htableDescr.setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName());
Conclusion
The full code is:
HTableDescriptor htableDescr = new HTableDescriptor(tableName);
HColumnDescriptor hcolumnDescr = new HColumnDescriptor(COLUMN_FAMILY);
htableDescr.addFamily(hcolumnDescr);
htableDescr.setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName());
byte[][] splitKeys = new RegionSplitter.HexStringSplit().split(n);
connection.getAdmin().createTable(htableDescr, splitKeys);