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