Multi-Point Region Division
Function
You can perform multi-point division by using org.apache.hadoop.hbase.client.HBaseAdmin. Note that the division operations take effect on empty regions only.
In this example, the multi-point division is performed on an HBase table by using multiSplit. The table will be split into 5 parts: "-∞~A", "A~D", "D~F", "F~H", and "H~+∞".
Example Code
The following code snippet belongs to the testMultiSplit method in the HBaseSample class of the com.huawei.bigdata.hbase.examples package.
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 (RegionInfo regionInfo : regionSet) {
admin.multiSplitSync(regionInfo.getRegionName(), sk);
}
LOG.info("MultiSplit successfully.");
} catch (Exception e) {
LOG.error("MultiSplit failed.");
} 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.");
} Note that the division operations take effect on empty regions only.
Last Article: Secondary Index-based Query
Next Article: Creating a Phoenix Table
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.