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

来源:互联网 发布:问道手游sf源码 编辑:程序博客网 时间:2024/06/06 01:22

         今天在使用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)

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


0 0
原创粉丝点击