本文主要是介绍HBase自定义Observer协处理器报错“ cannot be cast to org.apache.hadoop.hbase.client.HTable Cause:”,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
HBase自定义Observer协处理器在向其中一张表插入数据时,将数据保存到另一张表,执行逻辑报错如下
2021-11-30 14:28:13,884 ERROR [RpcServer.FifoWFPBQ.default.handler=29,queue=2,port=16000] master.MasterRpcServices: Region server linux121,16020,1638253313319 reported a fatal error:
ABORTING region server xxx,16020,1638253313319: The coprocessor com.wufabao.processor.MyProcessor threw java.lang.ClassCastException: org.apache.hadoop.hbase.client.HTableWrapper cannot be cast to org.apache.hadoop.hbase.client.HTable
Cause:
java.lang.ClassCastException: org.apache.hadoop.hbase.client.HTableWrapper cannot be cast to org.apache.hadoop.hbase.client.HTableat com.wufabao.processor.MyProcessor.prePut(MyProcessor.java:27)at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost$30.call(RegionCoprocessorHost.java:918)at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost$RegionOperation.call(RegionCoprocessorHost.java:1673)at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.execOperation(RegionCoprocessorHost.java:1749)at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.execOperation(RegionCoprocessorHost.java:1705)at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.prePut(RegionCoprocessorHost.java:914)at org.apache.hadoop.hbase.regionserver.HRegion.doPreMutationHook(HRegion.java:2997)at org.apache.hadoop.hbase.regionserver.HRegion.batchMutate(HRegion.java:2972)at org.apache.hadoop.hbase.regionserver.HRegion.batchMutate(HRegion.java:2918)at org.apache.hadoop.hbase.regionserver.RSRpcServices.doBatchOp(RSRpcServices.java:823)at org.apache.hadoop.hbase.regionserver.RSRpcServices.doNonAtomicRegionMutation(RSRpcServices.java:785)at org.apache.hadoop.hbase.regionserver.RSRpcServices.multi(RSRpcServices.java:2239)at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:34958)at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2339)at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:123)at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:188)at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:168)
原因
HTable tb1 = (HTable) e.getEnvironment().getTable(TableName.valueOf(“t2”));
原因是“=”后面返回的数据类型是HTableInterface,无法强制转换为HTable类型,因此报错,但是在IDE中提示HTableInterface已经过期,不建议把“=”左边的数据类型修改为HTableInterface类型
解决方案一
把“=”左边的数据类型改成HTableInterface继承的Table类型,经测试可以使用
Table t2 = e.getEnvironment().getTable(TableName.valueOf(“t2”));
解决方案二
不使用中间变量,直接获取到某张表的对象直接给该对象赋值
原代码:
HTable tb1 = (HTable) e.getEnvironment().getTable(TableName.valueOf("t2"));
tb1.put(put1);
现代码:
e.getEnvironment().getTable(TableName.valueOf("t2")).put(put1);
这篇关于HBase自定义Observer协处理器报错“ cannot be cast to org.apache.hadoop.hbase.client.HTable Cause:”的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!