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