HBASE预先分配regions的实现

本文介绍了如何在HBase中预先分配regions以优化负载均衡。通过一个实例展示了如何使用md5值将数据划分为300个region,并提供了创建表和生成split点的代码示例。预先创建regions能提升批量导入的性能,避免单个region过大导致的分裂问题。
摘要由CSDN通过智能技术生成

http://blog.csdn.net/yiboo/article/details/7284111

前面写了HBASE通过预先创建regions,来平衡数据的负载,其中用到了hbase官方的example

但是没有人告诉你怎么用

自己试了试用法

主要的就是如何分配rowkey start end之间的关系,因为我的数据的key是md5值,所以我使用了md5的两段分为300份

public static void main(String[] agrs) {
HBaseAdmin admin;
try {
admin = new HBaseAdmin(conf);
HTableDescriptor tableDesc = new HTableDescriptor("test");
byte[][] splits =getHexSplits("100000000000000000", "ffffffffffffffffffff",
300);
createTable( admin, tableDesc,splits);
} catch (MasterNotRunningException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


/**
* 默认情况下Hbase创建Table会新建一个region。执行批量导入,
* 意味着所有的client会写入这个region,直到这个region足够大,以至于分裂。
* 一个有效的提高批量导入的性能的方式,是预创建空的region
*/


public static boolean createTable(HBaseAdmin admin, HTableDescriptor table,
byte[][] splits) throws IOException {
try {
admin.createTable(table, splits);
return true;
} catch (TableExistsException e) {
LOG.info("table " + ta

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值