本帖最后由 pig2 于 2014-8-21 07:07 编辑
问题导读
1.协处理分为几种?
2.二者各有什么不同?
3.hbase coprocessor新版中做了哪些改变?
现在hbase的coprocessor有两种完全不同的实现,分别是observer模式与endpoint模式,它们分别对应2000和2001两个issue。我们可以将observer模式看成数据库中的触发器,而endpoint可以看成是存储过程。
关于coprocessor我们可以从类继承关系上看到,如下图所示:
共有旧版本中(0.92)三个Observer对象,即MasterObserver,RegionObserver和WALObserver,新版增加RegionServerObserver。它们的工作原理类似于钩子函数,在真实的函数实现前加入pre(),实现后加入post()方法,来实现对操作进行一些嵌入式的改变。
在新版本中,包括hbase0.96及hbase 0.985(其它版本尚未查看)增加了对象BaseRegionServerObserver
这个类功能:合并两个HRegion
hbase coprocessor的实现分为observer与endpoint,其中observer类似于触发器,主要在服务端工作,而endpoint类似于存储过程,主要在client端工作
observer可以实现权限管理、优先级设置、监控、ddl控制、二级索引等功能,而endpoint可以实现min、mas、avg、sum等功能
coprocessor可以动态加载
附上代码BaseRegionServerObserver代码:
- /*
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package org.apache.hadoop.hbase.coprocessor;
-
- import java.io.IOException;
- import java.util.List;
-
- import org.apache.hadoop.classification.InterfaceAudience;
- import org.apache.hadoop.classification.InterfaceStability;
- import org.apache.hadoop.hbase.CoprocessorEnvironment;
- import org.apache.hadoop.hbase.HBaseInterfaceAudience;
- import org.apache.hadoop.hbase.client.Mutation;
- import org.apache.hadoop.hbase.regionserver.HRegion;
-
- /**
- * An abstract class that implements RegionServerObserver.
- * By extending it, you can create your own region server observer without
- * overriding all abstract methods of RegionServerObserver.
- */
- @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
- @InterfaceStability.Evolving
- public class BaseRegionServerObserver implements RegionServerObserver {
-
- @Override
- public void preStopRegionServer(ObserverContext<RegionServerCoprocessorEnvironment> env)
- throws IOException { }
-
- @Override
- public void start(CoprocessorEnvironment env) throws IOException { }
-
- @Override
- public void stop(CoprocessorEnvironment env) throws IOException { }
-
- @Override
- public void preMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, HRegion regionA,
- HRegion regionB) throws IOException { }
-
- @Override
- public void postMerge(ObserverContext<RegionServerCoprocessorEnvironment> c, HRegion regionA,
- HRegion regionB, HRegion mergedRegion) throws IOException { }
-
- @Override
- public void preMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
- HRegion regionA, HRegion regionB, List<Mutation> metaEntries) throws IOException { }
-
- @Override
- public void postMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
- HRegion regionA, HRegion regionB, HRegion mergedRegion) throws IOException { }
-
- @Override
- public void preRollBackMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
- HRegion regionA, HRegion regionB) throws IOException { }
-
- @Override
- public void postRollBackMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
- HRegion regionA, HRegion regionB) throws IOException { }
-
- }
复制代码
|