hadoop-HBase-observer的一个样例
hbase(main):021:0> describe 'users'
DESCRIPTION ENABLED
{NAME => 'users', coprocessor$1 => 'file:///home/u/myjar/UsersObserver.jar|test.hbase.inaction.example5_2.Users true
Observer|1001|', FAMILIES => [{NAME => 'info', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPRESSION => 'N
ONE', VERSIONS => '3', TTL => '2147483647', MIN_VERSIONS => '0', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCK
CACHE => 'true'}]}
1 row(s) in 0.0610 seconds
先disable表。然后alert一下。那个1001是优先级。别忘记enable
disable 'users'
alter 'users', METHOD => 'table_att', 'coprocessor'=>'file:///home/u/mylib/UsersObserver.jar|test.hbase.inaction.example5_2.UsersObserver|1001|'
alter 'users', METHOD => 'table_att_unset',NAME => 'coprocessor$2'
删除
enable 'users'
hbase(main):022:0> scan 'users'
ROW COLUMN+CELL
id01 column=info:email, timestamp=1413963413002, value=wyj@gmail.com
id01 column=info:name, timestamp=1413963413002, value=wyj
id01 column=info:password, timestamp=1413963413002, value=000000
id01 column=info:user, timestamp=1413963413002, value=id01
id09 column=info:email, timestamp=1414566775616, value=test9@gmail.com
id09 column=info:name, timestamp=1414566775616, value=test9
id09 column=info:password, timestamp=1414566775616, value=9
id09 column=info:user, timestamp=1414566775616, value=id09
id99 column=info:email, timestamp=1414565339530, value=test99@gmail.com
id99 column=info:name, timestamp=1414565339530, value=test99
id99 column=info:password, timestamp=1414565339530, value======01=====
id99 column=info:user, timestamp=1414565339530, value=id99
invalID column=info:invalid_pass, timestamp=1414566775657, value=invalid_pass:9
11 row(s) in 0.1290 seconds
start() 和stop()这两个方法,在表enable和disable时分别也会相应运行
这start()和stop()在连接池里获得连接与释放连接实在是多余
observer类似触发器,操作一张表的时候要注意递归调用,拦截到一次put后再put这个表就会递归
这个样例就是这种,实际上没不论什么意义,就是个样例而已
注意锁。HBase是行级的锁,假设想put同一行是不会成功的
observer非常不好调试。仅仅能整一堆的log......
package test.hbase.inaction.example5_2; import java.io.IOException; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.HTablePool;
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;
import org.apache.hadoop.hbase.util.Bytes; import test.hbase.inaction.example2_4.User;
import test.hbase.inaction.example2_4.UsersDAO; /*
<span style="color:#ff0000;">先disable表,然后alert一下,那个1001是优先级,别忘记enable</span>
disable 'users'
alter 'users', METHOD => 'table_att', 'coprocessor'=>'file:///home/u/mylib/FollowsObserver.jar|test.hbase.inaction.example5_2.FollowsObserver|1001|'
alter 'users', METHOD => 'table_att_unset',NAME => 'coprocessor$2'<span style="white-space:pre"> </span>
enable 'users'
describe 'users'
*/
public class UsersObserver extends BaseRegionObserver { private final Log log = LogFactory.getLog(this.getClass()); private HTablePool pool = null; public void start(CoprocessorEnvironment env) throws IOException {
log.info("WYJ ---------------------------- start() begin");
pool = new HTablePool(env.getConfiguration(), Integer.MAX_VALUE);
log.info("pool=" + pool);
log.info("WYJ ---------------------------- start() end");
} public void stop(CoprocessorEnvironment env) throws IOException {
log.info("WYJ ---------------------------- stop() begin");
pool.close();
log.info("WYJ ---------------------------- stop() end");
} public void postPut(final ObserverContext<RegionCoprocessorEnvironment> e,
final Put put, final WALEdit edit, final boolean writeToWAL) {
log.info("WYJ: ================================================ postPut() begin");
try {
byte[] table = e.getEnvironment().getRegion().getRegionInfo()
.getTableName();
log.info("table=" + Bytes.toString(table));
if (!Bytes.equals(table, UsersDAO.TABLE_NAME)) {
return;
}
String pass = Bytes.toString(put.get(UsersDAO.INFO_FAM, UsersDAO.PASS_COL).get(0).getValue());
log.info("pass=" + pass);
byte[] user = put.get(UsersDAO.INFO_FAM, UsersDAO.USER_COL).get(0).getValue();
log.info("user=" + Bytes.toString(user));
if (pass == null || pass.length() < 6) {
log.info("password.length=" + pass.length());
UsersDAO dao = new UsersDAO(pool);
log.info("pool=" + pool);
dao.addUser("id99", "test99", "test99@gmail.com", "=====01=====");
log.info("dao.addUser(\"id99\", \"test99\", \"test99@gmail.com\", \"99999999\"); FINAL");
}
} catch (Exception ex) {
log.error(ex, ex);
}
log.info("WYJ: ================================================ postPut() end");
}
}
hadoop-HBase-observer的一个样例的更多相关文章
- 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:
使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...
- [推荐]Hadoop+HBase+Zookeeper集群的配置
[推荐]Hadoop+HBase+Zookeeper集群的配置 Hadoop+HBase+Zookeeper集群的配置 http://wenku.baidu.com/view/991258e881c ...
- hbase(ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet)
今天启动clouder manager集群时候hbase list出现 (ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException ...
- Cloudera集群中提交Spark任务出现java.lang.NoSuchMethodError: org.apache.hadoop.hbase.HTableDescriptor.addFamily错误解决
Cloudera及相关的组件版本 Cloudera: 5.7.0 Hbase: 1.20 Hadoop: 2.6.0 ZooKeeper: 3.4.5 就算是引用了相应的组件依赖,依然是报一样的错误! ...
- 【解决】org.apache.hadoop.hbase.ClockOutOfSyncException:
org.apache.hadoop.hbase.ClockOutOfSyncException: org.apache.hadoop.hbase.ClockOutOfSyncException: Se ...
- Hadoop,HBase,Zookeeper源码编译并导入eclipse
基本理念:尽可能的参考官方英文文档 Hadoop: http://wiki.apache.org/hadoop/FrontPage HBase: http://hbase.apache.org/b ...
- org.apache.hadoop.hbase.TableNotDisabledException 解决方法
Exception in thread "main" org.apache.hadoop.hbase.TableNotDisabledException: org.apache.h ...
- Java 向Hbase表插入数据报(org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apac)
org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apac 代码: //1.create HTa ...
- Hadoop,HBase集群环境搭建的问题集锦(四)
21.Schema.xml和solrconfig.xml配置文件里參数说明: 參考资料:http://www.hipony.com/post-610.html 22.执行时报错: 23., /comm ...
随机推荐
- 非洲儿童(南阳oj1036)(馋)
非洲小孩 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 家住非洲的小孩,都非常黑.为什么呢? 第一.他们地处热带,太阳辐射严重. 第二,他们不常常洗澡.(常年缺水, ...
- eclipse 安装vrapper vim插件
http://vrapper.sourceforge.net/update-site/stable 如果安装不上,设置下代理./window/pereference/network* - manul
- Android之Http通信——3.Android HTTP请求方式:HttpURLConnection
3.Android HTTP请求方式之HttpURLConnection 引言: 好了,前两节我们已经对HTTP协议进行了学习.相信看完前两节的朋友对HTTP协议相比之前 应该更加熟悉吧.好吧.学了要 ...
- Javascript 设计模式 辛格尔顿
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/30490955 我一直很喜欢Js,,,今天写JsSingleton模式来实现,以及 ...
- 鸽巢原理应用-分糖果 POJ 3370 Halloween treats
基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(二) Cryptography Application Block (高级)
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(二) Cryptography Application Block (高级) 本章介绍的是企业库加密应用程序模块 ...
- GUI测试要点
本人测试知识还不完整,所以下面的文字总结自网络上的文章,红色字体为我平时的测试经验,如有雷同之处,还请见谅,仅自己学习之用. 转载请说明来自博客园--邦邦酱好. ------------------- ...
- PyUnit框架学习
http://www.oschina.net/question/12_27127#INSTALL http://www.360doc.com/content/11/0606/23/54470_1221 ...
- MVC模块化架构
全面解析ASP.NET MVC模块化架构方案 什么叫架构?揭开架构神秘的面纱,无非就是:分层+模块化.任意复杂的架构,你也会发现架构师也就做了这两件事. 本文将会全面的介绍我们团队在模块化设计方面取得 ...
- Connecting Docker for Cloud Services using SDN and Network Virtualization
Abstract The explosive scale of container CPUs needs highly efficient network virtualization Chal ...