概述java
参考博客(http://blog.csdn.net/carl810224/article/details/52224441)编写EndPoint协处理器,编写完成后使用Maven打包(使用assembly插件,指定descriptorRefs值为jar-with-dependencies,将依赖的jar包也加进来),再将jar包上传到HDFS上,而后使用添加协处理器到指定表:git
disable 'test_table' alter 'test_table',METHOD=>'table_att','coprocessor'=>'hdfs://nameservice:/sum.jar|com.hbase.demo.endpoint.SumEndPoint|100' enable 'test_table' describe 'test_table'
卸载处理器:github
alter 'test_table',METHOD=>'table_att_unset',NAME=>'coprocessor$1'
coprocessor$1表示第一个协处理,能够经过describe命令查看表加载的处理器信息。google
使用alter添加endpoint以后,输入decribe查看表信息,发现表信息中心增长了coprocessor字段,事实上这并不表示已经加载成功。而后运行client程序,报错信息是spa
“hbase.ipc.CoprocessorRpcChannel:Call failed on IOException” “UnknownProtocolException:No registered coprocessor service found for name SumService in region test_table.......”
查看RegionServer日志,发现错误信息是 .net
“RegionCoprocessorHost:Failed to load coprocessor com.hbase.demo.endpoint.SumEndPoint” “java.lang.LinkageError:loader constraint violation in interface itable initialization:when resolving method
com.hbase.demo.endpoint.SumEndPoint.getService()Lcom/google/protobuf/Service;... the class loader......
have different Class objects for the type obuf/Service;used in the signature...."
实际上协处理器并无加载成功。插件
为何没有加载成功日志
“java.lang.LinkageError:loader constraint violation in interface itable initialization...”表示发生了jar包冲突,就是一个工程中不止1个jar包中包含了彻底相同的类,JVM不肯定应该使用哪一个jar包,解决办法就是直接删除多余jar包(确保jar包其他类不会被工程使用)。因为使用Maven的assembly插件打包时,选择了“jar-with-dependencies”的方式将依赖的全部jar包也打到了EndPoint中,在加载EndPoint时,EndPoint对应jar包中的类与HBase ClassPath中某个jar包对应的类彻底相同,JVM不肯定应该使用哪一个Jar包,所以加载不成功。code
怎么加载成功blog
找到了缘由,对应的解决方法就很简单了,去掉Maven的assembly插件中的“jar-with-dependencies”选项,仅将SumEndPoint.java和Sum.java打到jar包中,而后从新加载就能够了。
最后,Hbase 1.2.0使用protobuf做为RPC协议,所以须要首先下载protobuf变异.proto文件生成对应的.java文件,下载地址:github.com/google/protobuf/releases,Hbase 1.2.0对应protoc-2.5.0-win32.zip。下载完成后,进入bin目录,变异proto文件
proto --java_out=./ sum.proto