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 com.google.protobuf.Service; 021import java.io.IOException; 022import java.util.Collection; 023import java.util.List; 024import java.util.Map.Entry; 025import java.util.Optional; 026import java.util.concurrent.ConcurrentMap; 027import org.apache.hadoop.hbase.Abortable; 028import org.apache.hadoop.hbase.Server; 029import org.apache.hadoop.hbase.TableDescriptors; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.client.RegionInfo; 032import org.apache.hadoop.hbase.client.locking.EntityLock; 033import org.apache.hadoop.hbase.executor.ExecutorService; 034import org.apache.hadoop.hbase.io.hfile.BlockCache; 035import org.apache.hadoop.hbase.ipc.RpcServerInterface; 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.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.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode; 048 049/** 050 * A curated subset of services provided by {@link HRegionServer}. For use internally only. Passed 051 * to Managers, Services and Chores so can pass less-than-a full-on HRegionServer at test-time. Be 052 * judicious adding API. Changes cause ripples through the code base. 053 */ 054@InterfaceAudience.Private 055public interface RegionServerServices extends Server, MutableOnlineRegions, FavoredNodesForRegion { 056 057 /** Returns the WAL for a particular region. Pass null for getting the default (common) WAL */ 058 WAL getWAL(RegionInfo regionInfo) throws IOException; 059 060 /** Returns the List of WALs that are used by this server Doesn't include the meta WAL */ 061 List<WAL> getWALs() throws IOException; 062 063 /** 064 * @return Implementation of {@link FlushRequester} or null. Usually it will not be null unless 065 * during intialization. 066 */ 067 FlushRequester getFlushRequester(); 068 069 /** 070 * @return Implementation of {@link CompactionRequester} or null. Usually it will not be null 071 * unless during intialization. 072 */ 073 CompactionRequester getCompactionRequestor(); 074 075 /** Returns the RegionServerAccounting for this Region Server */ 076 RegionServerAccounting getRegionServerAccounting(); 077 078 /** Returns RegionServer's instance of {@link RegionServerRpcQuotaManager} */ 079 RegionServerRpcQuotaManager getRegionServerRpcQuotaManager(); 080 081 /** Returns RegionServer's instance of {@link SecureBulkLoadManager} */ 082 SecureBulkLoadManager getSecureBulkLoadManager(); 083 084 /** Returns RegionServer's instance of {@link RegionServerSpaceQuotaManager} */ 085 RegionServerSpaceQuotaManager getRegionServerSpaceQuotaManager(); 086 087 /** 088 * Context for postOpenDeployTasks(). 089 */ 090 class PostOpenDeployContext { 091 private final HRegion region; 092 private final long openProcId; 093 private final long masterSystemTime; 094 095 public PostOpenDeployContext(HRegion region, long openProcId, long masterSystemTime) { 096 this.region = region; 097 this.openProcId = openProcId; 098 this.masterSystemTime = masterSystemTime; 099 } 100 101 public HRegion getRegion() { 102 return region; 103 } 104 105 public long getOpenProcId() { 106 return openProcId; 107 } 108 109 public long getMasterSystemTime() { 110 return masterSystemTime; 111 } 112 } 113 114 /** 115 * Tasks to perform after region open to complete deploy of region on regionserver 116 * @param context the context 117 */ 118 void postOpenDeployTasks(final PostOpenDeployContext context) throws IOException; 119 120 class RegionStateTransitionContext { 121 private final TransitionCode code; 122 private final long openSeqNum; 123 private final long masterSystemTime; 124 private final long[] procIds; 125 private final RegionInfo[] hris; 126 127 public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long masterSystemTime, 128 RegionInfo... hris) { 129 this.code = code; 130 this.openSeqNum = openSeqNum; 131 this.masterSystemTime = masterSystemTime; 132 this.hris = hris; 133 this.procIds = new long[hris.length]; 134 } 135 136 public RegionStateTransitionContext(TransitionCode code, long openSeqNum, long procId, 137 long masterSystemTime, RegionInfo hri) { 138 this.code = code; 139 this.openSeqNum = openSeqNum; 140 this.masterSystemTime = masterSystemTime; 141 this.hris = new RegionInfo[] { hri }; 142 this.procIds = new long[] { procId }; 143 } 144 145 public TransitionCode getCode() { 146 return code; 147 } 148 149 public long getOpenSeqNum() { 150 return openSeqNum; 151 } 152 153 public long getMasterSystemTime() { 154 return masterSystemTime; 155 } 156 157 public RegionInfo[] getHris() { 158 return hris; 159 } 160 161 public long[] getProcIds() { 162 return procIds; 163 } 164 } 165 166 /** 167 * Notify master that a handler requests to change a region state 168 */ 169 boolean reportRegionStateTransition(final RegionStateTransitionContext context); 170 171 /** 172 * Returns a reference to the region server's RPC server 173 */ 174 RpcServerInterface getRpcServer(); 175 176 /** 177 * Get the regions that are currently being opened or closed in the RS 178 * @return map of regions in transition in this RS 179 */ 180 ConcurrentMap<byte[], Boolean> getRegionsInTransitionInRS(); 181 182 /** Returns The RegionServer's "Leases" service */ 183 LeaseManager getLeaseManager(); 184 185 /** Returns hbase executor service */ 186 ExecutorService getExecutorService(); 187 188 /** 189 * Only required for "old" log replay; if it's removed, remove this. 190 * @return The RegionServer's NonceManager 191 */ 192 ServerNonceManager getNonceManager(); 193 194 /** 195 * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to be 196 * available for handling 197 * @param service the {@code Service} subclass instance to expose as a coprocessor endpoint 198 * @return {@code true} if the registration was successful, {@code false} 199 */ 200 boolean registerService(Service service); 201 202 /** Returns heap memory manager instance */ 203 HeapMemoryManager getHeapMemoryManager(); 204 205 /** 206 * @return the max compaction pressure of all stores on this regionserver. The value should be 207 * greater than or equal to 0.0, and any value greater than 1.0 means we enter the 208 * emergency state that some stores have too many store files. 209 * @see org.apache.hadoop.hbase.regionserver.Store#getCompactionPressure() 210 */ 211 double getCompactionPressure(); 212 213 /** Returns the controller to avoid flush too fast */ 214 ThroughputController getFlushThroughputController(); 215 216 /** 217 * @return the flush pressure of all stores on this regionserver. The value should be greater than 218 * or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that 219 * global memstore size already exceeds lower limit. 220 */ 221 @Deprecated 222 double getFlushPressure(); 223 224 /** Returns the metrics tracker for the region server */ 225 MetricsRegionServer getMetrics(); 226 227 /** 228 * Master based locks on namespaces/tables/regions. 229 */ 230 EntityLock regionLock(List<RegionInfo> regionInfos, String description, Abortable abort) 231 throws IOException; 232 233 /** 234 * Unassign the given region from the current regionserver and assign it randomly. Could still be 235 * assigned to us. This is used to solve some tough problems for which you need to reset the state 236 * of a region. For example, if you hit FileNotFound exception and want to refresh the store file 237 * list. 238 * <p> 239 * See HBASE-17712 for more details. 240 */ 241 void unassign(byte[] regionName) throws IOException; 242 243 /** Returns True if cluster is up; false if cluster is not up (we are shutting down). */ 244 boolean isClusterUp(); 245 246 /** Returns Return table descriptors implementation. */ 247 TableDescriptors getTableDescriptors(); 248 249 /** Returns The block cache instance. */ 250 Optional<BlockCache> getBlockCache(); 251 252 /** Returns The cache for mob files. */ 253 Optional<MobFileCache> getMobFileCache(); 254 255 /** Returns the {@link AccessChecker} */ 256 AccessChecker getAccessChecker(); 257 258 /** Returns {@link ZKPermissionWatcher} */ 259 ZKPermissionWatcher getZKPermissionWatcher(); 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}