欢迎投稿

今日深度:

【Hbase批量插入数据】,--insertor

【Hbase批量插入数据】,--insertor


一.批量插入数据(hbase用户执行,不可以调整key)

-- create 'ns_zj001:bigTab','f01'

-- put 'ns_zj001:bigTab','001','f01:name','zhangsan'

java -cp ./hbase-tools-1.0.jar:`hbase classpath` com.suning.tools.Tools -zk hbase01-dev.cnsuning.com,hbase02-dev.cnsuning.com,hbase03-dev.cnsuning.com:2015:/hbase -put -batch 150 -threads 5 -count 1000 -speed 3 -table zj001:tabTestAgain -fq f01:name

说明:

1.hbase-tools-1.0.jar下载地址 hbase+批量上传jar包-Java文档类资源-CSDN下载hbase+批量上传jar包更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/zhujunqtp/86503732

2.依次为固定格式,集群信息

3.batch一个线程一次性插入条数,thread线程数,count总条数,table表名,fq列名(列族:列名)

二.linux环境执行shell批量插入

echo "create 'zj001:tmp110','f',{NUMREGIONS => 20, SPLITALGO => 'HexStringSplit'}" | hbase shell

for i in $(seq 1 100000); do a=`uuidgen`;echo "put 'zj002:tmp01','$a','f:name','$a'"; done | hbase shell   -- 平均插入 100000 条数据

-- 数据落盘
echo "flush 'zj001:tmp110'" | hbase shell               

三.利用ycsb插入数据,雅虎性能测试工具(key可控,效率更高)

ycsb工具:hbase+ycsb工具-Java文档类资源-CSDN下载hbase+ycsb工具更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/zhujunqtp/86503738

-- 创建表 20个分区
hbase(main):001:0> n_splits = 20      --分区数量
hbase(main):002:0> create 'ns_zjpre:tmp80', 'f', {SPLITS => (1..n_splits).map {|i| "user#{1000+i*(9999-1000)/n_splits}"}}   -创建分区表

-- fieldlength 单个 value大小 1kb,一行可以粗略认为是1kb数据
-- operationcount 操作数   209715200 = 1024 * 1024 * 200 = 200G
-- insertcount 插入数         209715200 = 1024 * 1024 * 200 = 200G

ycsb 安装地址 /home/hbase/ycsb-hbase12-binding-0.14.0
[hbase@namenode1-pst-xg ycsb-hbase12-binding-0.14.0]$ pwd
/home/hbase/ycsb-hbase12-binding-0.14.0
脚本在/home/hbase/ycsb-hbase12-binding-0.14.0/bin下面

执行:
./ycsb.sh run hbase12 -p workload=com.yahoo.ycsb.workloads.CoreWorkload -p table=ns_zjpre:tmp80 -p columnfamily=f -p clientbuffering=true -p fieldcount=1 -p fieldlength=1024

-p updateproportion=1 -p readproportion=0 -p insertproportion=0 -p writeallfields=true -p insertorder=hashed -p requestdistribution=zipfian -p operationcount=209715200-p insertcount=209715200 

-p zeropadding=9 -threads 30 -s

说明:

1.-- operationcount ,insertcount操作数 209715200为具体数,不能是表达式,=前后不能含有空格,否则无法识别

2..ycsb 造的数据 rowKey格式是 user[0-9]+

3.updateproportion=1,表示为纯插入模式

operationcount 是要操作的数量,insertcount 是插入数据的范围,为了保证数据尽可能覆盖每个分区,可将insertcount 设置的大一点,比如999999999

requestdistribution=uniform,数据均匀分布

--insertorder=ordered,requestdistribution=sequential
insertorder=ordered,不会产生数据碰撞
requestdistribution=sequential,能保证每条数据的rowKey 是唯一的

zeropadding 控制 前面是否填充0

recordcount 插入条数

insertorder=ordered + zeropadding=9 => 1 会生成 user000000001,如果生成的 数据总条数小于 1000 然后 zeropadding 设置4 那么会生成 user0001 ~user1000 的数据 user1x ~ user9x 的分区 就都是空的。

--insertorder=hashed,requestdistribution=zipfian
insertorder=hashed 这个会对生成的rowKey 做hash,大数据量的情况下可能碰撞 导致数据被覆盖,所以实际的数据量可能小于你设置的值
requestdistribution=zipfian,这个是生成rowKey的策略 ,含有一定随机性,不能保证每条数据的rowKey 是唯一的

4.

/hbase/data/ns_bdptrt/table_100part1/fe96ccf8802c1c8381c3296fdb7984fb/f/ns_bdptrt=table_100part1_20200109205217215=7b41f2ced80ce2d564f2b26b776daac4-24c5ea5f85fe4e4a87945320a16cc1f7_SeqId_4_

table_100part1_20200109205217215 这个archive下面的数据被 table_100part1 引用了,所以会一直存在 直到 hbase 下一次合并。所以基本上archive 里面的东西 都不需要管,hbase 会自动处理

5.写数据,region做compact都会移动文件

6.

保证分区数和位数对应:

n_splits = 200 # HBase recommends (10 * number of regionservers)
n_step = 9999 / n_splits
create 'ns_test:test_1y',{NAME => 'f', COMPRESSION => 'LZO'}, {SPLITS => (1..(n_splits-1)).map {|i| "user#{"%04d"% (i * n_step)}"}}

7.

truncate tablename:不保留预分区
truncate_preserve tablename:保留预分区

www.htsjk.Com true http://www.htsjk.com/hbase/45990.html NewsArticle 【Hbase批量插入数据】,--insertor 一.批量插入数据 hbase用户执行不可以调整key -- create ns_zj001:bigTab,f01 -- put ns_zj001:bigTab,001,f01:name,zhangsan java -cp ./hbase-tools-1.0.jar:hbase classpath com.suning.tool...
评论暂时关闭