hbase coprocessor 提供了并行计算能力,有效地减少了客户端的压力,充分利用分析式计算的优势。
测试目标:在插入表中的某个列族时,如果发现列族的中未含有相关列,则自送添加上。
(1)hbase创建表
create 'uuidtest', {NAME => 'refrigerator', VERSIONS => 1}, {NAME => 'aircondition', VERSIONS => 1},{NAME => 'washer', VERSIONS => 1}
(2)上传coprocessor到hdfs
hadoop fs -put -f CRM_HbaseCoprocessor-0.0.1-SNAPSHOT-jar-with-dependencies.jar /hbase/coprocessor
(3)修改上述文件相关权限,可以让hbase 进程访问。
(4)添加coprocessor
disable 'uuidtest'
alter 'uuidtest',METHOD => 'table_att','coprocessor'=>'hdfs:///hbase/CRM_HbaseCoprocessor-0.0.1-SNAPSHOT-jar-with-dependencies.jar|com.hisense.crm.TestCoprocessor|1001|mysqlIP=10.18.222.58,mysqlUser=hitv,mysqlPassword=hitv'
enable 'uuidtest'
desc 'uuidtest'
查看hbase 表的属性,确认是否添加成功。
hbase(main):001:0> describe 'uuidtest'
Table uuidtest is ENABLED
uuidtest, {TABLE_ATTRIBUTES => {coprocessor$1 => 'hdfs:///hbase/CRM_HbaseCoprocessor-0.0.1-SNAPSHOT-jar-with-dependencies.jar|com.hisense.crm.TestCoprocessor|1001|mysqlIP=10.18.222.58,mysqlUser=hitv,mysqlPassword=hitv'}
COLUMN FAMILIES DESCRIPTION
{NAME => 'aircondition', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE =
> '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'refrigerator', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE =
> '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'washer', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '655
36', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
(5)插入数据
put 'uuidtest','9005_1551411799','aircondition:indoor_temp_sensor','1'
(6)查看数据
(7)解绑coprocessor
disable 'uuidtest'
alter 'uuidtest', METHOD => 'table_att_unset',NAME => 'coprocessor$1'
enable 'uuidtest'
desc 'uuidtest'