001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.regionserver;
020
021import java.io.IOException;
022import java.util.Collection;
023import java.util.List;
024import java.util.Map.Entry;
025import java.util.Optional;
026import java.util.concurrent.ConcurrentMap;
027import org.apache.hadoop.hbase.Abortable;
028import org.apache.hadoop.hbase.Server;
029import org.apache.hadoop.hbase.TableDescriptors;
030import org.apache.hadoop.hbase.TableName;
031import org.apache.hadoop.hbase.client.RegionInfo;
032import org.apache.hadoop.hbase.client.locking.EntityLock;
033import org.apache.hadoop.hbase.executor.ExecutorService;
034import org.apache.hadoop.hbase.io.hfile.BlockCache;
035import org.apache.hadoop.hbase.ipc.RpcServerInterface;
036import org.apache.hadoop.hbase.mob.MobFileCache;
037import org.apache.hadoop.hbase.quotas.RegionServerRpcQuotaManager;
038import org.apache.hadoop.hbase.quotas.RegionServerSpaceQuotaManager;
039import org.apache.hadoop.hbase.quotas.RegionSizeStore;
040import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequester;
041import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
042import org.apache.hadoop.hbase.security.access.AccessChecker;
043import org.apache.hadoop.hbase.security.access.ZKPermissionWatcher;
044import org.apache.hadoop.hbase.wal.WAL;
045import org.apache.yetus.audience.InterfaceAudience;
046
047import org.apache.hbase.thirdparty.com.google.protobuf.Service;
048
049import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
050
051/**
052 * A curated subset of services provided by {@link HRegionServer}.
053 * For use internally only. Passed to Managers, Services and Chores so can pass less-than-a
054 * full-on HRegionServer at test-time. Be judicious adding API. Changes cause ripples through
055 * the code base.
056 */
057@InterfaceAudience.Private
058public interface RegionServerServices extends Server, MutableOnlineRegions, FavoredNodesForRegion {
059
060  /** @return the WAL for a particular region. Pass null for getting the
061   * default (common) WAL */
062  WAL getWAL(RegionInfo regionInfo) throws IOException;
063
064  /** @return the List of WALs that are used by this server
065   *  Doesn't include the meta WAL
066   */
067  List<WAL> getWALs() throws IOException;
068
069  /**
070   * @return Implementation of {@link FlushRequester} or null. Usually it will not be null unless
071   *         during intialization.
072   */
073  FlushRequester getFlushRequester();
074
075  /**
076   * @return Implementation of {@link CompactionRequester} or null. Usually it will not be null
077   *         unless during intialization.
078   */
079  CompactionRequester getCompactionRequestor();
080
081  /**
082   * @return the RegionServerAccounting for this Region Server
083   */
084  RegionServerAccounting getRegionServerAccounting();
085
086  /**
087   * @return RegionServer's instance of {@link RegionServerRpcQuotaManager}
088   */
089  RegionServerRpcQuotaManager getRegionServerRpcQuotaManager();
090
091  /**
092   * @return RegionServer's instance of {@link SecureBulkLoadManager}
093   */
094  SecureBulkLoadManager getSecureBulkLoadManager();
095
096  /**
097   * @return RegionServer's instance of {@link RegionServerSpaceQuotaManager}
098   */
099  RegionServerSpaceQuotaManager getRegionServerSpaceQuotaManager();
100
101  /**
102   * Context for postOpenDeployTasks().
103   */
104  class PostOpenDeployContext {
105    private final HRegion region;
106    private final long openProcId;
107    private final long masterSystemTime;
108
109    public PostOpenDeployContext(HRegion region, long openProcId, long masterSystemTime) {
110      this.region = region;
111      this.openProcId = openProcId;
112      this.masterSystemTime = masterSystemTime;
113    }
114
115    public HRegion getRegion() {
116      return region;
117    }
118
119    public long getOpenProcId() {
120      return openProcId;
121    }
122
123    public long getMasterSystemTime() {
124      return masterSystemTime;
125    }
126  }
127
128  /**
129   * Tasks to perform after region open to complete deploy of region on regionserver
130   * @param context the context
131   */
132  void postOpenDeployTasks(final PostOpenDeployContext context) throws IOException;
133
134  class RegionStateTransitionContext {
135    private final TransitionCode code;
136    private final long openSeqNum;
137    private final long masterSystemTime;
138    private final long[] procIds;
139    private final RegionInfo[] hris;
140
141    public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long masterSystemTime,
142        RegionInfo... hris) {
143      this.code = code;
144      this.openSeqNum = openSeqNum;
145      this.masterSystemTime = masterSystemTime;
146      this.hris = hris;
147      this.procIds = new long[hris.length];
148    }
149
150    public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long procId,
151        long masterSystemTime, RegionInfo hri) {
152      this.code = code;
153      this.openSeqNum = openSeqNum;
154      this.masterSystemTime = masterSystemTime;
155      this.hris = new RegionInfo[] { hri };
156      this.procIds = new long[] { procId };
157    }
158
159    public TransitionCode getCode() {
160      return code;
161    }
162
163    public long getOpenSeqNum() {
164      return openSeqNum;
165    }
166
167    public long getMasterSystemTime() {
168      return masterSystemTime;
169    }
170
171    public RegionInfo[] getHris() {
172      return hris;
173    }
174
175    public long[] getProcIds() {
176      return procIds;
177    }
178  }
179
180  /**
181   * Notify master that a handler requests to change a region state
182   */
183  boolean reportRegionStateTransition(final RegionStateTransitionContext context);
184
185  /**
186   * Returns a reference to the region server's RPC server
187   */
188  RpcServerInterface getRpcServer();
189
190  /**
191   * Get the regions that are currently being opened or closed in the RS
192   * @return map of regions in transition in this RS
193   */
194  ConcurrentMap<byte[], Boolean> getRegionsInTransitionInRS();
195
196  /**
197   * @return The RegionServer's "Leases" service
198   */
199  LeaseManager getLeaseManager();
200
201  /**
202   * @return hbase executor service
203   */
204  ExecutorService getExecutorService();
205
206  /**
207   * Only required for "old" log replay; if it's removed, remove this.
208   * @return The RegionServer's NonceManager
209   */
210  ServerNonceManager getNonceManager();
211
212  /**
213   * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to be
214   * available for handling
215   * @param service the {@code Service} subclass instance to expose as a coprocessor endpoint
216   * @return {@code true} if the registration was successful, {@code false}
217   */
218  boolean registerService(Service service);
219
220  /**
221   * @return heap memory manager instance
222   */
223  HeapMemoryManager getHeapMemoryManager();
224
225  /**
226   * @return the max compaction pressure of all stores on this regionserver. The value should be
227   *         greater than or equal to 0.0, and any value greater than 1.0 means we enter the
228   *         emergency state that some stores have too many store files.
229   * @see org.apache.hadoop.hbase.regionserver.Store#getCompactionPressure()
230   */
231  double getCompactionPressure();
232
233  /**
234   * @return the controller to avoid flush too fast
235   */
236  ThroughputController getFlushThroughputController();
237
238  /**
239   * @return the flush pressure of all stores on this regionserver. The value should be greater than
240   *         or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that
241   *         global memstore size already exceeds lower limit.
242   */
243  @Deprecated
244  double getFlushPressure();
245
246  /**
247   * @return the metrics tracker for the region server
248   */
249  MetricsRegionServer getMetrics();
250
251  /**
252   * Master based locks on namespaces/tables/regions.
253   */
254  EntityLock regionLock(List<RegionInfo> regionInfos, String description,
255      Abortable abort) throws IOException;
256
257  /**
258   * Unassign the given region from the current regionserver and assign it randomly. Could still be
259   * assigned to us. This is used to solve some tough problems for which you need to reset the state
260   * of a region. For example, if you hit FileNotFound exception and want to refresh the store file
261   * list.
262   * <p>
263   * See HBASE-17712 for more details.
264   */
265  void unassign(byte[] regionName) throws IOException;
266
267  /**
268   * Reports the provided Region sizes hosted by this RegionServer to the active Master.
269   *
270   * @param sizeStore The sizes for Regions locally hosted.
271   * @return {@code false} if reporting should be temporarily paused, {@code true} otherwise.
272   */
273  boolean reportRegionSizesForQuotas(RegionSizeStore sizeStore);
274
275  /**
276   * Reports a collection of files, and their sizes, that belonged to the given {@code table} were
277   * just moved to the archive directory.
278   *
279   * @param tableName The name of the table that files previously belonged to
280   * @param archivedFiles Files and their sizes that were moved to archive
281   * @return {@code true} if the files were successfully reported, {@code false} otherwise.
282   */
283  boolean reportFileArchivalForQuotas(
284      TableName tableName, Collection<Entry<String,Long>> archivedFiles);
285
286  /**
287   * @return True if cluster is up; false if cluster is not up (we are shutting down).
288   */
289  boolean isClusterUp();
290
291  /**
292   * @return Return the object that implements the replication source executorService.
293   */
294  ReplicationSourceService getReplicationSourceService();
295
296  /**
297   * @return Return table descriptors implementation.
298   */
299  TableDescriptors getTableDescriptors();
300
301  /**
302   * @return The block cache instance.
303   */
304  Optional<BlockCache> getBlockCache();
305
306  /**
307   * @return The cache for mob files.
308   */
309  Optional<MobFileCache> getMobFileCache();
310
311  /**
312   * @return the {@link AccessChecker}
313   */
314  AccessChecker getAccessChecker();
315
316  /**
317   * @return {@link ZKPermissionWatcher}
318   */
319  ZKPermissionWatcher getZKPermissionWatcher();
320}