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