多语言展示
当前在线:896今日阅读:167今日分享:16

Region如何预建分区

hbase数据表的key的分布情况,就可以在建表的时候对hbase进行region的预分区
工具/原料
1

规划hbase预分区

2

hbase shell中建分区表,指定分区文件

方法/步骤
1

在hbase shell中直接输入create:Examples:    Create a table with namespace=ns1 and table qualifier=t1    hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}    Create a table with namespace=default and table qualifier=t1    hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}    hbase> # The above in shorthand would be the following:    hbase> create 't1', 'f1', 'f2', 'f3'    hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}    hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}      Table configuration options can be put at the end.  Examples:      hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']    hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']    hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'    hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }    hbase> # Optionally pre-split the table into NUMREGIONS, using    hbase> # SPLITALGO ('HexStringSplit', 'UniformSplit' or classname)    hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}    hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}    hbase> create 't1', {NAME => 'f1'}, {NAME => 'if1', LOCAL_INDEX=>'COMBINE_INDEX|INDEXED=f1:q1:8|rowKey:rowKey:10,UPDATE=true'}

2

可以通过指定SPLITS_FILE的值指定分区文件,如果分区信息比较少,也可以直接用SPLITS分区。我们可以通过如下命令建一个分区表,指定第一步中生成的分区文件:create 'split_table_test', 'cf', {SPLITS_FILE => 'region_split_info.txt'}

3

对hbase表做一个SNAPPY压缩create 'split_table_test',{NAME =>'cf', COMPRESSION => 'SNAPPY'}, {SPLITS_FILE => 'region_split_info.txt'}

注意事项

要将分区的参数指定单独用一个大括号扩起来

推荐信息