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 com.google.protobuf.Service;
22
23 import java.io.IOException;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.concurrent.ConcurrentMap;
27
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.hbase.classification.InterfaceAudience;
33 import org.apache.hadoop.hbase.classification.InterfaceStability;
34 import org.apache.hadoop.hbase.executor.ExecutorService;
35 import org.apache.hadoop.hbase.ipc.RpcServerInterface;
36 import org.apache.hadoop.hbase.master.TableLockManager;
37 import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
38 import org.apache.hadoop.hbase.quotas.RegionServerQuotaManager;
39 import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
40 import org.apache.hadoop.hbase.wal.WAL;
41 import org.apache.zookeeper.KeeperException;
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 * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to be
211 * available for handling
212 * @param service the {@code Service} subclass instance to expose as a coprocessor endpoint
213 * @return {@code true} if the registration was successful, {@code false}
214 */
215 boolean registerService(Service service);
216
217 /**
218 * @return heap memory manager instance
219 */
220 HeapMemoryManager getHeapMemoryManager();
221
222 /**
223 * @return the max compaction pressure of all stores on this regionserver. The value should be
224 * greater than or equal to 0.0, and any value greater than 1.0 means we enter the
225 * emergency state that some stores have too many store files.
226 * @see org.apache.hadoop.hbase.regionserver.Store#getCompactionPressure()
227 */
228 double getCompactionPressure();
229
230 /**
231 * @return all the online tables in this RS
232 */
233 Set<TableName> getOnlineTables();
234
235 /**
236 * @return the controller to avoid flush too fast
237 */
238 ThroughputController getFlushThroughputController();
239
240 /**
241 * @return the flush pressure of all stores on this regionserver. The value should be greater than
242 * or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that
243 * global memstore size already exceeds lower limit.
244 */
245 double getFlushPressure();
246
247 /**
248 * @return the metrics tracker for the region server
249 */
250 MetricsRegionServer getMetrics();
251
252 /**
253 * Unassign the given region from the current regionserver and assign it randomly. Could still be
254 * assigned to us. This is used to solve some tough problems for which you need to reset the state
255 * of a region. For example, if you hit FileNotFound exception and want to refresh the store file
256 * list.
257 * <p>
258 * See HBASE-17712 for more details.
259 */
260 void unassign(byte[] regionName) throws IOException;
261 }