创建HBase表Region
功能简介
一般通过org.apache.hadoop.hbase.client.HBaseAdmin进行多点分割。注意:分割操作只对空Region起作用。
本例使用multiSplit进行多点分割将HBase表按照“-∞~A”、“A~D”、“D~F”、“F~H”、“H~+∞”分为五个Region。
代码样例
以下代码片段在com.huawei.bigdata.hbase.examples包的“HBaseSample”类的testMultiSplit方法中。
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."); }
注意:分割操作只对空Region起作用。