我按照这个做法,为啥put数据后,索引表没有自动插入数据呢?hbase日志里也提示协议处理器加载成功了,“Loaded coprocessor test.HbaseCoprocessor from HTD of test successfully.”
以下是代码,其中testi是索引表,test是数据表
create 'testi', {NAME=>'keys'}
create 'test', {NAME=>'info'}
alter 'test',METHOD=>'table_att','coprocessor'=>'hdfs:///user/dw/myhbase-0.0.1-SNAPSHOT.jar|test.HbaseCoprocessor|1001'
put 'test','row1','info:1','hello0'
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());
// Put indexPut = new Put("hello");
indexPut.add("keys".getBytes(), "1".getBytes(),
tmp.getRow());
table.put(indexPut);
}
table.close();
}
} |