HBase EndPoint加载失败

概述

  参考博客(http://blog.csdn.net/carl810224/article/details/52224441)编写EndPoint协处理器,编写完成后使用Maven打包(使用assembly插件,指定descriptorRefs值为jar-with-dependencies,将依赖的jar包也加进来),再将jar包上传到HDFS上,然后使用添加协处理器到指定表:

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'

卸载处理器:

alter 'test_table',METHOD=>'table_att_unset',NAME=>'coprocessor$1'

coprocessor$1表示第一个协处理,可以通过describe命令查看表加载的处理器信息。

  使用alter添加endpoint之后,输入decribe查看表信息,发现表信息中心增加了coprocessor字段,事实上这并不表示已经加载成功。然后运行client程序,报错信息是

“hbase.ipc.CoprocessorRpcChannel:Call failed on IOException”

“UnknownProtocolException:No registered coprocessor service found for name SumService in region test_table.......”

  查看RegionServer日志,发现错误信息是     

“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包,因此加载不成功。

怎么加载成功

   找到了原因,对应的解决方法就很简单了,去掉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

 

posted @ 2017-09-23 13:46  lz3018  阅读(1219)  评论(1编辑  收藏  举报