HBase 协处理器实现二级索引
来源:互联网 发布:基于svd的推荐算法 编辑:程序博客网 时间:2024/05/16 11:29
HBase在0.92之后引入了coprocessors,提供了一系列的钩子,让我们能够轻易实现访问控制和二级索引的特性。下面简单介绍下两种coprocessors,第一种是Observers,它实际类似于触发器,第二种是Endpoint,它类似与存储过程。由于这里只用到了Observers,所以只介绍Observers,想要更详细的介绍请查阅(https://blogs.apache.org/hbase/entry/coprocessor_introduction)。observers分为三种:
RegionObserver:提供数据操作事件钩子;
WALObserver:提供WAL(write ahead log)相关操作事件钩子;
MasterObserver:提供DDL操作事件钩子。
相关接口请参阅hbase api。
下面给出一个例子,该例子使用RegionObserver实现在写主表之前将索引数据先写到另外一个表:
package com.dengchuanhua.testhbase;import java.io.IOException; import java.util.Iterator; import java.util.List;import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; 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.regionserver.wal.WALEdit;public class TestCoprocessor extends BaseRegionObserver {@Override 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...HTable table = new HTable(conf, "indexTableName"); List<KeyValue> kv = put.get("familyName".getBytes(), "columnName".getBytes()); Iterator<KeyValue> kvItor = kv.iterator(); while (kvItor.hasNext()) { KeyValue tmp = kvItor.next(); Put indexPut = new Put(tmp.getValue()); indexPut.add("familyName".getBytes(), "columnName".getBytes(), tmp.getRow()); table.put(indexPut); } table.close(); }}
写完后要加载到table里面去,先把该文件打包成test.jar并上传到hdfs的/demo路径下,然后操作如下:
1. disable ‘testTable’
2. alter ‘testTable’, METHOD=>’table_att’,’coprocessor’=>’hdfs:///demo/test.jar|com.dengchuanhua.testhbase.TestCoprocessor|1001′
3. enable ‘testTable’
然后往testTable里面插数据就会自动往indexTableName写数据了。
总结:本文主要介绍了一个用coprocessor实现二级索引的例子。
- HBase 协处理器实现二级索引
- Hbase用协处理器建二级索引
- hbase 二级索引实现
- HBase 实现二级索引
- 用Hbase实现二级索引
- HBase + Solr Cloud实现HBase二级索引
- HBase + Solr Cloud实现HBase二级索引
- 基于solr实现hbase的二级索引
- 基于solr实现hbase的二级索引
- hbase二级索引
- Hbase- 二级索引
- hbase二级索引
- 关于hbase二级索引
- hbase二级索引
- HBase创建二级索引
- hbase二级索引
- HBase二级索引
- Hbase solr 二级索引
- 我要买爱疯5S呀
- VS2012快捷键
- 记录去年的面试
- HBase 二级索引与Join
- 第十三周-输入一个整数,要求输出对应的二进制形式。
- HBase 协处理器实现二级索引
- 浅谈ssh整合1
- Android属性(android:gravity)的说明
- Ubuntu软件包管理:
- cocos2d-x客户端与Java服务器的通信(一)
- 浅谈ssh整合2
- 获取表中列的详细信息
- Linux WWW 服务器
- Android--eclipse DDMS导出文件失败--android Failed to push the item