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