标签:协处理器
分为两种类型
observer 观察者相当于触发器
Endpoint终端相当于存储过程
下面的观察者实现查询之前替换掉行键为Jack的KeyValue
import java.io.IOException; import java.util.List; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.util.Bytes; public class RegionObserverTest extends BaseRegionObserver { private static byte[] fixed_rowkey = "Jack".getBytes(); @Override public void postGet(ObserverContext<RegionCoprocessorEnvironment> c, Get get, List<KeyValue> result) throws IOException { if (Bytes.equals(get.getRow(), fixed_rowkey)) { KeyValue kv = new KeyValue(get.getRow(), Bytes.toBytes("time"), Bytes.toBytes("time"), Bytes.toBytes(System .currentTimeMillis())); result.add(kv); } } }
加载协处理器命令
disable ‘students‘ alter ‘students‘ ,‘coprocessor‘=>‘hdfs://ns1/coprocessor.jar|com.hbase.RegionObserverTest||‘ enable ‘students‘
本文出自 “一无所有 QQ:934033381” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1699113
标签:协处理器
原文地址:http://tianxingzhe.blog.51cto.com/3390077/1699113