使用hbase coprocessor未生效
测试表
create 'test', {NAME=>'info'}
索引表
create 'testi', {NAME=>'keys'}
alter 'test',METHOD=>'table_att','coprocessor'=>'hdfs://ip:端口/user/hl/test/myhbase.jar|test.HbaseCoprocessor|1001'
往test表put数据
put 'test','row1','info:1','hello0'
发现索引表testi是没有数据
scan 'testi'
在hbase日志里grep日志出来Loaded coprocessor是成功的
regionserver.RegionCoprocessorHost: Loaded coprocessor test.HbaseCoprocessor from HTD of test successfully.
test.HbaseCoprocessor源代码
public class HbaseCoprocessor extends BaseRegionObserver {
public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e,
final Put put, final WALEdit edit, final boolean writeToWAL)
throws IOException {
// set configuration
Configuration conf = new Configuration();
// need conf.set...
String colName = "1";
HTable table = new HTable(conf, "testi");
List<Cell> kv = put.get("info".getBytes(), "1".getBytes());
Iterator<Cell> kvItor = kv.iterator();
while (kvItor.hasNext()) {
Cell tmp = kvItor.next();
Put indexPut = new Put(tmp.getValue());
indexPut.add("keys".getBytes(), "1".getBytes(),
tmp.getRow());
table.put(indexPut);
}
table.close();
}
}
|
|