HBase的协处理器问题,prePut函数无法触发。

本文详细介绍了在使用HBase的协处理器时,如何正确使用prePut方法进行预插入操作,并通过实例代码说明了常见问题及其解决策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         今天在使用HBase的协处理器的时候,遇到了问题,使用的是prePut方法,相当于触发器。从网上找了个例子,如下:

public class TestCoprocessor extends BaseRegionObserver {
@Override
public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e,
final Put put, final WALEdit edit, final boolean writeToWAL)
throws IOException {
Configuration conf = new Configuration();
HTable table = new HTable(conf, "index_table");
List<KeyValue> kv = put.get("data".getBytes(), "name".getBytes());
Iterator<KeyValue> kvItor = kv.iterator();
while (kvItor.hasNext()) {
KeyValue tmp = kvItor.next();
Put indexPut = new Put(tmp.getValue());
indexPut.add("index".getBytes(), tmp.getRow(), Bytes.toBytes(System.currentTimeMillis()));
table.put(indexPut);
}
table.close();
}


打包成jar file,然后上传即可,详细的看这里:

http://www.aboutyun.com/thread-8857-1-1.html

可是怎么都成功不了,函数就是不触发。最后,发现,函数错了。用例子中的函数根本就不是覆盖。我这里用的是hbase0.98.6.

于是根据提示修改函数为:

public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e,
Put put, WALEdit edit, Durability durability)

其他的不用变,这样才成功了。。。。。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值