View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.coprocessor;
21  
22  import java.util.concurrent.ConcurrentMap;
23  
24  import org.apache.hadoop.hbase.CoprocessorEnvironment;
25  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26  import org.apache.hadoop.hbase.HRegionInfo;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.classification.InterfaceStability;
29  import org.apache.hadoop.hbase.metrics.MetricRegistry;
30  import org.apache.hadoop.hbase.regionserver.Region;
31  import org.apache.hadoop.hbase.regionserver.RegionServerServices;
32  
33  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
34  @InterfaceStability.Evolving
35  public interface RegionCoprocessorEnvironment extends CoprocessorEnvironment {
36    /** @return the region associated with this coprocessor */
37    Region getRegion();
38  
39    /** @return region information for the region this coprocessor is running on */
40    HRegionInfo getRegionInfo();
41  
42    /** @return reference to the region server services */
43    RegionServerServices getRegionServerServices();
44  
45    /** @return shared data between all instances of this coprocessor */
46    ConcurrentMap<String, Object> getSharedData();
47  
48    /**
49     * Returns a MetricRegistry that can be used to track metrics at the region server level. All
50     * metrics tracked at this level will be shared by all the coprocessor instances
51     * of the same class in the same region server process. Note that there will be one
52     * region coprocessor environment per region in the server, but all of these instances will share
53     * the same MetricRegistry. The metric instances (like Counter, Timer, etc) will also be shared
54     * among all of the region coprocessor instances.
55     *
56     * <p>See ExampleRegionObserverWithMetrics class in the hbase-examples modules to see examples of how
57     * metrics can be instantiated and used.</p>
58     * @return A MetricRegistry for the coprocessor class to track and export metrics.
59     */
60    // Note: we are not exposing getMetricRegistryForRegion(). per-region metrics are already costly
61    // so we do not want to allow coprocessors to export metrics at the region level. We can allow
62    // getMetricRegistryForTable() to allow coprocessors to track metrics per-table, per-regionserver.
63    MetricRegistry getMetricRegistryForRegionServer();
64  
65  
66  }