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  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.io.IOException;
22  import java.util.Map;
23  import java.util.Set;
24  import java.util.concurrent.ConcurrentMap;
25  
26  import org.apache.hadoop.fs.FileSystem;
27  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
28  import org.apache.hadoop.hbase.HRegionInfo;
29  import org.apache.hadoop.hbase.TableName;
30  import org.apache.hadoop.hbase.classification.InterfaceAudience;
31  import org.apache.hadoop.hbase.classification.InterfaceStability;
32  import org.apache.hadoop.hbase.executor.ExecutorService;
33  import org.apache.hadoop.hbase.ipc.RpcServerInterface;
34  import org.apache.hadoop.hbase.master.TableLockManager;
35  import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
36  import org.apache.hadoop.hbase.quotas.RegionServerQuotaManager;
37  import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
38  import org.apache.hadoop.hbase.wal.WAL;
39  import org.apache.zookeeper.KeeperException;
40  
41  import com.google.protobuf.Service;
42  
43  /**
44   * Services provided by {@link HRegionServer}
45   */
46  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
47  @InterfaceStability.Evolving
48  public interface RegionServerServices extends OnlineRegions, FavoredNodesForRegion {
49    /**
50     * @return True if this regionserver is stopping.
51     */
52    boolean isStopping();
53  
54    /** @return the WAL for a particular region. Pass null for getting the
55     * default (common) WAL */
56    WAL getWAL(HRegionInfo regionInfo) throws IOException;
57  
58    /**
59     * @return Implementation of {@link CompactionRequestor} or null.
60     */
61    CompactionRequestor getCompactionRequester();
62  
63    /**
64     * @return Implementation of {@link FlushRequester} or null.
65     */
66    FlushRequester getFlushRequester();
67  
68    /**
69     * @return the RegionServerAccounting for this Region Server
70     */
71    RegionServerAccounting getRegionServerAccounting();
72  
73    /**
74     * @return RegionServer's instance of {@link TableLockManager}
75     */
76    TableLockManager getTableLockManager();
77  
78    /**
79     * @return RegionServer's instance of {@link RegionServerQuotaManager}
80     */
81    RegionServerQuotaManager getRegionServerQuotaManager();
82  
83    /**
84     * Context for postOpenDeployTasks().
85     */
86    class PostOpenDeployContext {
87      private final Region region;
88      private final long masterSystemTime;
89  
90      @InterfaceAudience.Private
91      public PostOpenDeployContext(Region region, long masterSystemTime) {
92        this.region = region;
93        this.masterSystemTime = masterSystemTime;
94      }
95      public Region getRegion() {
96        return region;
97      }
98      public long getMasterSystemTime() {
99        return masterSystemTime;
100     }
101   }
102 
103   /**
104    * Tasks to perform after region open to complete deploy of region on
105    * regionserver
106    *
107    * @param context the context
108    * @throws KeeperException
109    * @throws IOException
110    */
111   void postOpenDeployTasks(final PostOpenDeployContext context) throws KeeperException, IOException;
112 
113   /**
114    * Tasks to perform after region open to complete deploy of region on
115    * regionserver
116    *
117    * @param r Region to open.
118    * @throws KeeperException
119    * @throws IOException
120    * @deprecated use {@link #postOpenDeployTasks(PostOpenDeployContext)}
121    */
122   @Deprecated
123   void postOpenDeployTasks(final Region r) throws KeeperException, IOException;
124 
125   class RegionStateTransitionContext {
126     private final TransitionCode code;
127     private final long openSeqNum;
128     private final long masterSystemTime;
129     private final HRegionInfo[] hris;
130 
131     @InterfaceAudience.Private
132     public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long masterSystemTime,
133         HRegionInfo... hris) {
134       this.code = code;
135       this.openSeqNum = openSeqNum;
136       this.masterSystemTime = masterSystemTime;
137       this.hris = hris;
138     }
139     public TransitionCode getCode() {
140       return code;
141     }
142     public long getOpenSeqNum() {
143       return openSeqNum;
144     }
145     public long getMasterSystemTime() {
146       return masterSystemTime;
147     }
148     public HRegionInfo[] getHris() {
149       return hris;
150     }
151   }
152 
153   /**
154    * Notify master that a handler requests to change a region state
155    */
156   boolean reportRegionStateTransition(final RegionStateTransitionContext context);
157 
158   /**
159    * Notify master that a handler requests to change a region state
160    * @deprecated use {@link #reportRegionStateTransition(RegionStateTransitionContext)}
161    */
162   @Deprecated
163   boolean reportRegionStateTransition(TransitionCode code, long openSeqNum, HRegionInfo... hris);
164 
165   /**
166    * Notify master that a handler requests to change a region state
167    * @deprecated use {@link #reportRegionStateTransition(RegionStateTransitionContext)}
168    */
169   @Deprecated
170   boolean reportRegionStateTransition(TransitionCode code, HRegionInfo... hris);
171 
172   /**
173    * Returns a reference to the region server's RPC server
174    */
175   RpcServerInterface getRpcServer();
176 
177   /**
178    * Get the regions that are currently being opened or closed in the RS
179    * @return map of regions in transition in this RS
180    */
181   ConcurrentMap<byte[], Boolean> getRegionsInTransitionInRS();
182 
183   /**
184    * @return Return the FileSystem object used by the regionserver
185    */
186   FileSystem getFileSystem();
187 
188   /**
189    * @return The RegionServer's "Leases" service
190    */
191   Leases getLeases();
192 
193   /**
194    * @return hbase executor service
195    */
196   ExecutorService getExecutorService();
197 
198   /**
199    * @return set of recovering regions on the hosting region server
200    */
201   Map<String, Region> getRecoveringRegions();
202 
203   /**
204    * Only required for "old" log replay; if it's removed, remove this.
205    * @return The RegionServer's NonceManager
206    */
207   public ServerNonceManager getNonceManager();
208 
209   /**
210    * @return all the online tables in this RS
211    */
212   Set<TableName> getOnlineTables();
213 
214 
215   /**
216    * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to be
217    * available for handling
218    * @param service the {@code Service} subclass instance to expose as a coprocessor endpoint
219    * @return {@code true} if the registration was successful, {@code false}
220    */
221   boolean registerService(Service service);
222 
223   /**
224    * @return heap memory manager instance
225    */
226   HeapMemoryManager getHeapMemoryManager();
227 
228   /**
229    * @return the max compaction pressure of all stores on this regionserver. The value should be
230    *         greater than or equal to 0.0, and any value greater than 1.0 means we enter the
231    *         emergency state that some stores have too many store files.
232    * @see org.apache.hadoop.hbase.regionserver.Store#getCompactionPressure()
233    */
234   double getCompactionPressure();
235 
236   /**
237    * @return the controller to avoid flush too fast
238    */
239   ThroughputController getFlushThroughputController();
240 
241   /**
242    * @return the flush pressure of all stores on this regionserver. The value should be greater than
243    *         or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that
244    *         global memstore size already exceeds lower limit.
245    */
246   double getFlushPressure();
247 }