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