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