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