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.mob.MobFileCache; 036import org.apache.hadoop.hbase.quotas.RegionServerRpcQuotaManager; 037import org.apache.hadoop.hbase.quotas.RegionServerSpaceQuotaManager; 038import org.apache.hadoop.hbase.quotas.RegionSizeStore; 039import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequester; 040import org.apache.hadoop.hbase.regionserver.regionreplication.RegionReplicationBufferManager; 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}. For use internally only. Passed 053 * to Managers, Services and Chores so can pass less-than-a full-on HRegionServer at test-time. Be 054 * judicious adding API. Changes cause ripples through the code base. 055 */ 056@InterfaceAudience.Private 057public interface RegionServerServices extends Server, MutableOnlineRegions, FavoredNodesForRegion { 058 059 /** 060 * @return the WAL for a particular region. Pass null for getting the default (common) WAL 061 */ 062 WAL getWAL(RegionInfo regionInfo) throws IOException; 063 064 /** 065 * @return the List of WALs that are used by this server 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, Abortable abort) 255 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 * @param sizeStore The sizes for Regions locally hosted. 270 * @return {@code false} if reporting should be temporarily paused, {@code true} otherwise. 271 */ 272 boolean reportRegionSizesForQuotas(RegionSizeStore sizeStore); 273 274 /** 275 * Reports a collection of files, and their sizes, that belonged to the given {@code table} were 276 * just moved to the archive directory. 277 * @param tableName The name of the table that files previously belonged to 278 * @param archivedFiles Files and their sizes that were moved to archive 279 * @return {@code true} if the files were successfully reported, {@code false} otherwise. 280 */ 281 boolean reportFileArchivalForQuotas(TableName tableName, 282 Collection<Entry<String, Long>> archivedFiles); 283 284 /** 285 * @return True if cluster is up; false if cluster is not up (we are shutting down). 286 */ 287 boolean isClusterUp(); 288 289 /** 290 * @return Return the object that implements the replication source executorService. 291 */ 292 ReplicationSourceService getReplicationSourceService(); 293 294 /** 295 * @return Return table descriptors implementation. 296 */ 297 TableDescriptors getTableDescriptors(); 298 299 /** 300 * @return The block cache instance. 301 */ 302 Optional<BlockCache> getBlockCache(); 303 304 /** 305 * @return The cache for mob files. 306 */ 307 Optional<MobFileCache> getMobFileCache(); 308 309 /** 310 * @return the {@link AccessChecker} 311 */ 312 AccessChecker getAccessChecker(); 313 314 /** 315 * @return {@link ZKPermissionWatcher} 316 */ 317 ZKPermissionWatcher getZKPermissionWatcher(); 318 319 RegionReplicationBufferManager getRegionReplicationBufferManager(); 320 321 @Override 322 HRegion getRegion(String encodedRegionName); 323 324 @Override 325 List<HRegion> getRegions(TableName tableName) throws IOException; 326 327 @Override 328 List<HRegion> getRegions(); 329}