07预分区

本文最后更新于 2021-08-05 11:42:59

预分区

通常情况下,每次建表时,默认只有一个region!随着这个region的数据不断增多,region会自动切分

自动切分: 讲当前region中的所有的rowkey进行排序,排序后取start-key和stopkey中间rowkey,由这个rowkey一分为二,一分为二后,生成两个region,新增的Region会交给其他的RS负责,目的是为了达到负载均衡,但是通常往往会适得其反!

为例避免某些热点Region同时分配到同一个RegionServer,可以在建表时,自己提前根据数据的特征规划region!

手动指定分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 按照边界指定分区
create 'staff1','info','partition1',SPLITS => ['1000','2000','3000','4000']
# 指定15个分区 按照16进制序列划分
create 'staff2','info','partition2',{NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
插入时rowkey先转换为16进制,负载均衡效果可能要好一些

# 按照文件中设置的规则划分
create 'staff3','partition3',SPLITS_FILE => 'splits.txt'

>> splits.txt
aaaa
bbbb
cccc
dddd

API指定分区

1
2
3
4
// The start key specified will become the end key of the first region of the table, and the end key specified will become the start key of the last region of the table 
admin.createTable(TableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
//
admin.createTable(TableDescriptor desc, byte[][] splitKeys)

07预分区
https://jiajun.xyz/2020/11/07/bigdata/03hbase/07预分区/
作者
Lambda
发布于
2020年11月7日
更新于
2021年8月5日
许可协议