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