Multi-Point Region Splitting
Function Description
You can perform multi-point splitting by using org.apache.hadoop.hbase.client.HBaseAdmin.
The splitting operation takes effect on empty regions only.
In MRS 2.0.0 or later, the API is removed and does not support this function. You can pre-partition a table when creating the table or directly perform split operations in some regions.
In this example, the multi-point splitting is performed on an HBase table by using multiSplit. The table will be split into four regions: "A~D", "D~F", "F~H", and "H~Z".
Sample Code
The following code snippets are in the testMultiSplit method in the HBaseExample class of the com.huawei.bigdata.hbase.examples packet.
public void testMultiSplit() {
LOG.info("Entering testMultiSplit.");
Table table = null;
Admin admin = null;
try {
admin = conn.getAdmin();
// initilize a HTable object
table = conn.getTable(tableName);
Set<HRegionInfo> regionSet = new HashSet<HRegionInfo>();
List<HRegionLocation> regionList = conn.getRegionLocator(tableName).getAllRegionLocations();
for (HRegionLocation hrl : regionList) {
regionSet.add(hrl.getRegionInfo());
}
byte[][] sk = new byte[4][];
sk[0] = "A".getBytes();
sk[1] = "D".getBytes();
sk[2] = "F".getBytes();
sk[3] = "H".getBytes();
for (HRegionInfo regionInfo : regionSet) {
((HBaseAdmin) admin).multiSplit(regionInfo.getRegionName(), sk);
}
LOG.info("MultiSplit successfully.");
} catch (Exception e) {
LOG.error("MultiSplit failed ", e);
} finally {
if (table != null) {
try {
// Close table object
table.close();
} catch (IOException e) {
LOG.error("Close table failed ", e);
}
}
if (admin != null) {
try {
// Close the Admin object.
admin.close();
} catch (IOException e) {
LOG.error("Close admin failed ", e);
}
}
}
LOG.info("Exiting testMultiSplit.");
} Last Article: Reading MOB Data
Next Article: ACL Security Configuration
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.