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     * @return RegionServer's instance of {@link SecureBulkLoadManager}
85     */
86    SecureBulkLoadManager getSecureBulkLoadManager();
87
88    /**
89     * Context for postOpenDeployTasks().
90     */
91    class PostOpenDeployContext {
92      private final Region region;
93      private final long masterSystemTime;
94
95      @InterfaceAudience.Private
96      public PostOpenDeployContext(Region region, long masterSystemTime) {
97        this.region = region;
98        this.masterSystemTime = masterSystemTime;
99      }
100     public Region getRegion() {
101       return region;
102     }
103     public long getMasterSystemTime() {
104       return masterSystemTime;
105     }
106   }
107
108   /**
109    * Tasks to perform after region open to complete deploy of region on
110    * regionserver
111    *
112    * @param context the context
113    * @throws KeeperException
114    * @throws IOException
115    */
116   void postOpenDeployTasks(final PostOpenDeployContext context) throws KeeperException, IOException;
117
118   /**
119    * Tasks to perform after region open to complete deploy of region on
120    * regionserver
121    *
122    * @param r Region to open.
123    * @throws KeeperException
124    * @throws IOException
125    * @deprecated use {@link #postOpenDeployTasks(PostOpenDeployContext)}
126    */
127   @Deprecated
128   void postOpenDeployTasks(final Region r) throws KeeperException, IOException;
129
130   class RegionStateTransitionContext {
131     private final TransitionCode code;
132     private final long openSeqNum;
133     private final long masterSystemTime;
134     private final HRegionInfo[] hris;
135
136     @InterfaceAudience.Private
137     public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long masterSystemTime,
138         HRegionInfo... hris) {
139       this.code = code;
140       this.openSeqNum = openSeqNum;
141       this.masterSystemTime = masterSystemTime;
142       this.hris = hris;
143     }
144     public TransitionCode getCode() {
145       return code;
146     }
147     public long getOpenSeqNum() {
148       return openSeqNum;
149     }
150     public long getMasterSystemTime() {
151       return masterSystemTime;
152     }
153     public HRegionInfo[] getHris() {
154       return hris;
155     }
156   }
157 
158   /**
159    * Notify master that a handler requests to change a region state
160    */
161   boolean reportRegionStateTransition(final RegionStateTransitionContext context);
162
163   /**
164    * Notify master that a handler requests to change a region state
165    * @deprecated use {@link #reportRegionStateTransition(RegionStateTransitionContext)}
166    */
167   @Deprecated
168   boolean reportRegionStateTransition(TransitionCode code, long openSeqNum, HRegionInfo... hris);
169
170   /**
171    * Notify master that a handler requests to change a region state
172    * @deprecated use {@link #reportRegionStateTransition(RegionStateTransitionContext)}
173    */
174   @Deprecated
175   boolean reportRegionStateTransition(TransitionCode code, HRegionInfo... hris);
176 
177   /**
178    * Returns a reference to the region server's RPC server
179    */
180   RpcServerInterface getRpcServer();
181
182   /**
183    * Get the regions that are currently being opened or closed in the RS
184    * @return map of regions in transition in this RS
185    */
186   ConcurrentMap<byte[], Boolean> getRegionsInTransitionInRS();
187 
188   /**
189    * @return Return the FileSystem object used by the regionserver
190    */
191   FileSystem getFileSystem();
192 
193   /**
194    * @return The RegionServer's "Leases" service
195    */
196   Leases getLeases();
197 
198   /**
199    * @return hbase executor service
200    */
201   ExecutorService getExecutorService();
202 
203   /**
204    * @return set of recovering regions on the hosting region server
205    */
206   Map<String, Region> getRecoveringRegions();
207
208   /**
209    * Only required for "old" log replay; if it's removed, remove this.
210    * @return The RegionServer's NonceManager
211    */
212   public ServerNonceManager getNonceManager();
213 
214   /**
215    * @return all the online tables in this RS
216    */
217   Set<TableName> getOnlineTables();
218
219
220   /**
221    * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to be
222    * available for handling
223    * @param service the {@code Service} subclass instance to expose as a coprocessor endpoint
224    * @return {@code true} if the registration was successful, {@code false}
225    */
226   boolean registerService(Service service);
227 
228   /**
229    * @return heap memory manager instance
230    */
231   HeapMemoryManager getHeapMemoryManager();
232
233   /**
234    * @return the max compaction pressure of all stores on this regionserver. The value should be
235    *         greater than or equal to 0.0, and any value greater than 1.0 means we enter the
236    *         emergency state that some stores have too many store files.
237    * @see org.apache.hadoop.hbase.regionserver.Store#getCompactionPressure()
238    */
239   double getCompactionPressure();
240 
241   /**
242    * @return the controller to avoid flush too fast
243    */
244   ThroughputController getFlushThroughputController();
245
246   /**
247    * @return the flush pressure of all stores on this regionserver. The value should be greater than
248    *         or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that
249    *         global memstore size already exceeds lower limit.
250    */
251   double getFlushPressure();
252
253   /**
254    * @return the metrics tracker for the region server
255    */
256   MetricsRegionServer getMetrics();
257 }