Hbase的热点问题





hbase热点
1、一张表最初只有一个region
2、实际工作中可能会创建多个region(预分区)


五、hbase rowkey设计
1、长度原则
rowkey的长度就是大小,最长:64KB,一般建议:10-100个字节
rowkey不宜过长
2、个数原则:列簇不能过多
3、散列原则
将多个字段进行组合
timestamp+uuid 容易引发热点问题 适合于经常通过时间检索的业务场景

uuid+timestamp 适合按照账号信息进行检索的业务场景
110_20170610142230
110_20171210142230
4、索引表
timestamp+uuid
原来的rowkey
110_20170610142230

index -》rowkey
20170610142230_110
col:110_20170610142230

难点:源表和索引表的数据同步

反转字段
20170610142230_110
142230  032241
下一秒
132241

region 0000-2000
split:
region1:0000-1000 没有上限
region2:1001-2000 没有下限
2001-》 region2
....
3000-》 region2    split    
region2-1:1001-2000
region2-2:2001-3000


-》导致region的浪费,存在热点问题


hbase预分区
create 't1', 'f1', SPLITS => ['10', '20', '30', '40'] --数字代表rowkey的前缀不是具体的值。 5001放在 40 这个region 这边 3001 放在30这个 region这边
create 't2', 'f1', SPLITS_FILE => '/opt/moduels/hbase-0.98.6-hadoop2/splits.txt'
JAVA代码实现:
static final Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin = null;
admin = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(weibo_content));
byte[][] splitKeys = { Bytes.toBytes("100"), Bytes.toBytes("200"), Bytes.toBytes("300") };
admin.createTable(desc, splitKeys);