分享

hbase高级编程:hbase(新版) 0.985协处理器中的BaseRegionServerObserver

本帖最后由 pig2 于 2014-8-21 07:07 编辑

问题导读
1.协处理分为几种?
2.二者各有什么不同?
3.hbase coprocessor新版中做了哪些改变?






现在hbase的coprocessor有两种完全不同的实现,分别是observer模式与endpoint模式,它们分别对应2000和2001两个issue。我们可以将observer模式看成数据库中的触发器,而endpoint可以看成是存储过程。

关于coprocessor我们可以从类继承关系上看到,如下图所示:

2012-03-13-10-31-41.jpg



共有旧版本中(0.92)三个Observer对象,即MasterObserver,RegionObserver和WALObserver,新版增加RegionServerObserver。它们的工作原理类似于钩子函数,在真实的函数实现前加入pre(),实现后加入post()方法,来实现对操作进行一些嵌入式的改变。


在新版本中,包括hbase0.96hbase 0.985(其它版本尚未查看)增加了对象BaseRegionServerObserver
这个类功能:合并两个HRegion



hbase coprocessor的实现分为observer与endpoint,其中observer类似于触发器,主要在服务端工作,而endpoint类似于存储过程,主要在client端工作
observer可以实现权限管理、优先级设置、监控、ddl控制、二级索引等功能,而endpoint可以实现min、mas、avg、sum等功能
coprocessor可以动态加载


附上代码BaseRegionServerObserver代码:
  1. /*
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. *     http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. package org.apache.hadoop.hbase.coprocessor;
  16. import java.io.IOException;
  17. import java.util.List;
  18. import org.apache.hadoop.classification.InterfaceAudience;
  19. import org.apache.hadoop.classification.InterfaceStability;
  20. import org.apache.hadoop.hbase.CoprocessorEnvironment;
  21. import org.apache.hadoop.hbase.HBaseInterfaceAudience;
  22. import org.apache.hadoop.hbase.client.Mutation;
  23. import org.apache.hadoop.hbase.regionserver.HRegion;
  24. /**
  25. * An abstract class that implements RegionServerObserver.
  26. * By extending it, you can create your own region server observer without
  27. * overriding all abstract methods of RegionServerObserver.
  28. */
  29. @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
  30. @InterfaceStability.Evolving
  31. public class BaseRegionServerObserver implements RegionServerObserver {
  32.   @Override
  33.   public void preStopRegionServer(ObserverContext<RegionServerCoprocessorEnvironment> env)
  34.       throws IOException { }
  35.   @Override
  36.   public void start(CoprocessorEnvironment env) throws IOException { }
  37.   @Override
  38.   public void stop(CoprocessorEnvironment env) throws IOException { }
  39.   @Override
  40.   public void preMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, HRegion regionA,
  41.       HRegion regionB) throws IOException { }
  42.   @Override
  43.   public void postMerge(ObserverContext<RegionServerCoprocessorEnvironment> c, HRegion regionA,
  44.       HRegion regionB, HRegion mergedRegion) throws IOException { }
  45.   @Override
  46.   public void preMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
  47.       HRegion regionA, HRegion regionB, List<Mutation> metaEntries) throws IOException { }
  48.   @Override
  49.   public void postMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
  50.       HRegion regionA, HRegion regionB, HRegion mergedRegion) throws IOException { }
  51.   @Override
  52.   public void preRollBackMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
  53.       HRegion regionA, HRegion regionB) throws IOException { }
  54.   @Override
  55.   public void postRollBackMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
  56.       HRegion regionA, HRegion regionB) throws IOException { }
  57. }
复制代码











已有(8)人评论

跳转到指定楼层
mr.andy 发表于 2014-8-21 09:06:42
楼主, 之前遇到一个面试题, 关于hbase, 怎么做多表关联查询?除了用hive同步hbase做映射之外, 还有其他办法吗?  
回复

使用道具 举报

xiqiang_chen 发表于 2014-8-21 10:33:13
赞一个~感谢分享~
回复

使用道具 举报

pig2 发表于 2014-8-21 11:08:51
mr.andy 发表于 2014-8-21 09:06
楼主, 之前遇到一个面试题, 关于hbase, 怎么做多表关联查询?除了用hive同步hbase做映射之外, 还有其他办法 ...

hbase多表关联查询很难做,目前没有完美的方案,可以看看二级索引。
回复

使用道具 举报

mr.andy 发表于 2014-8-23 17:23:56
pig2 发表于 2014-8-21 11:08
hbase多表关联查询很难做,目前没有完美的方案,可以看看二级索引。

好的 谢谢.
回复

使用道具 举报

ainubis 发表于 2015-3-29 03:00:58
O(∩_∩)O谢谢分享
回复

使用道具 举报

超超大猴子 发表于 2015-5-20 16:22:03
回复

使用道具 举报

a_zhen 发表于 2015-9-7 15:26:25
正在研究,真好啊
回复

使用道具 举报

yangyufans 发表于 2016-10-31 19:32:40
传参之后如何接收
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条