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.client; 019 020import java.io.IOException; 021import java.util.List; 022import java.util.function.Supplier; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HRegionLocation; 025import org.apache.hadoop.hbase.MasterNotRunningException; 026import org.apache.hadoop.hbase.RegionLocations; 027import org.apache.hadoop.hbase.ServerName; 028import org.apache.hadoop.hbase.TableName; 029import org.apache.hadoop.hbase.ZooKeeperConnectionException; 030import org.apache.hadoop.hbase.client.backoff.ClientBackoffPolicy; 031import org.apache.hadoop.hbase.ipc.RpcControllerFactory; 032import org.apache.hadoop.hbase.security.User; 033import org.apache.yetus.audience.InterfaceAudience; 034 035import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService; 036import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService; 037 038/** Internal methods on Connection that should not be used by user code. */ 039@InterfaceAudience.Private 040// NOTE: Although this class is public, this class is meant to be used directly from internal 041// classes and unit tests only. 042public interface ClusterConnection extends Connection { 043 044 /** 045 * Key for configuration in Configuration whose value is the class we implement making a new 046 * Connection instance. 047 */ 048 String HBASE_CLIENT_CONNECTION_IMPL = "hbase.client.connection.impl"; 049 050 /** 051 * @return - true if the master server is running 052 * @deprecated this has been deprecated without a replacement 053 */ 054 @Deprecated 055 boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException; 056 057 /** 058 * Use this api to check if the table has been created with the specified number of splitkeys 059 * which was used while creating the given table. Note : If this api is used after a table's 060 * region gets splitted, the api may return false. tableName splitKeys used while creating table 061 * if a remote or network exception occurs 062 */ 063 boolean isTableAvailable(TableName tableName, byte[][] splitKeys) throws IOException; 064 065 /** 066 * A table that isTableEnabled == false and isTableDisabled == false is possible. This happens 067 * when a table has a lot of regions that must be processed. 068 * @param tableName table name 069 * @return true if the table is enabled, false otherwise 070 * @throws IOException if a remote or network exception occurs 071 */ 072 boolean isTableEnabled(TableName tableName) throws IOException; 073 074 /** 075 * Check if a table is disabled. 076 * @param tableName table name 077 * @return true if the table is disabled, false otherwise 078 * @throws IOException if a remote or network exception occurs 079 */ 080 boolean isTableDisabled(TableName tableName) throws IOException; 081 082 /** 083 * Retrieve TableState, represent current table state. 084 * @param tableName table state for 085 * @return state of the table 086 */ 087 TableState getTableState(TableName tableName) throws IOException; 088 089 /** 090 * Find the location of the region of <i>tableName</i> that <i>row</i> lives in. 091 * @param tableName name of the table <i>row</i> is in 092 * @param row row key you're trying to find the region of 093 * @return HRegionLocation that describes where to find the region in question 094 * @throws IOException if a remote or network exception occurs 095 */ 096 HRegionLocation locateRegion(final TableName tableName, final byte[] row) throws IOException; 097 098 /** 099 * Clear the region location cache. 100 * @deprecated {@link #clearRegionLocationCache()} instead. 101 */ 102 @Deprecated 103 default void clearRegionCache() { 104 clearRegionLocationCache(); 105 } 106 107 void cacheLocation(final TableName tableName, final RegionLocations location); 108 109 /** 110 * Allows flushing the region cache of all locations that pertain to <code>tableName</code> 111 * @param tableName Name of the table whose regions we are to remove from cache. 112 */ 113 void clearRegionCache(final TableName tableName); 114 115 /** 116 * Find the location of the region of <i>tableName</i> that <i>row</i> lives in, ignoring any 117 * value that might be in the cache. 118 * @param tableName name of the table <i>row</i> is in 119 * @param row row key you're trying to find the region of 120 * @return HRegionLocation that describes where to find the region in question 121 * @throws IOException if a remote or network exception occurs 122 */ 123 HRegionLocation relocateRegion(final TableName tableName, final byte[] row) throws IOException; 124 125 /** 126 * Find the location of the region of <i>tableName</i> that <i>row</i> lives in, ignoring any 127 * value that might be in the cache. 128 * @param tableName name of the table <i>row</i> is in 129 * @param row row key you're trying to find the region of 130 * @param replicaId the replicaId of the region 131 * @return RegionLocations that describe where to find the region in question 132 * @throws IOException if a remote or network exception occurs 133 */ 134 RegionLocations relocateRegion(final TableName tableName, final byte[] row, int replicaId) 135 throws IOException; 136 137 /** 138 * Update the location cache. This is used internally by HBase, in most cases it should not be 139 * used by the client application. 140 * @param tableName the table name 141 * @param regionName the region name 142 * @param rowkey the row 143 * @param exception the exception if any. Can be null. 144 * @param source the previous location 145 */ 146 void updateCachedLocations(TableName tableName, byte[] regionName, byte[] rowkey, 147 Object exception, ServerName source); 148 149 /** 150 * Gets the location of the region of <i>regionName</i>. 151 * @param regionName name of the region to locate 152 * @return HRegionLocation that describes where to find the region in question 153 * @throws IOException if a remote or network exception occurs 154 */ 155 HRegionLocation locateRegion(final byte[] regionName) throws IOException; 156 157 /** 158 * Gets the locations of all regions in the specified table, <i>tableName</i>. 159 * @param tableName table to get regions of 160 * @return list of region locations for all regions of table 161 * @throws IOException if IO failure occurs 162 */ 163 List<HRegionLocation> locateRegions(final TableName tableName) throws IOException; 164 165 /** 166 * Gets the locations of all regions in the specified table, <i>tableName</i>. 167 * @param tableName table to get regions of 168 * @param useCache Should we use the cache to retrieve the region information. 169 * @param offlined True if we are to include offlined regions, false and we'll leave out offlined 170 * regions from returned list. 171 * @return list of region locations for all regions of table 172 * @throws IOException if IO failure occurs 173 */ 174 List<HRegionLocation> locateRegions(final TableName tableName, final boolean useCache, 175 final boolean offlined) throws IOException; 176 177 /** 178 * Gets the locations of the region in the specified table, <i>tableName</i>, for a given row. 179 * @param tableName table to get regions of 180 * @param row the row 181 * @param useCache Should we use the cache to retrieve the region information. 182 * @param retry do we retry 183 * @return region locations for this row. 184 * @throws IOException if IO failure occurs 185 */ 186 RegionLocations locateRegion(TableName tableName, byte[] row, boolean useCache, boolean retry) 187 throws IOException; 188 189 /** 190 * Gets the locations of the region in the specified table, <i>tableName</i>, for a given row. 191 * @param tableName table to get regions of 192 * @param row the row 193 * @param useCache Should we use the cache to retrieve the region information. 194 * @param retry do we retry 195 * @param replicaId the replicaId for the region 196 * @return region locations for this row. 197 * @throws IOException if IO failure occurs 198 */ 199 RegionLocations locateRegion(TableName tableName, byte[] row, boolean useCache, boolean retry, 200 int replicaId) throws IOException; 201 202 /** 203 * Returns a {@link MasterKeepAliveConnection} to the active master 204 */ 205 MasterKeepAliveConnection getMaster() throws IOException; 206 207 /** 208 * Get the admin service for master. 209 */ 210 AdminService.BlockingInterface getAdminForMaster() throws IOException; 211 212 /** 213 * Establishes a connection to the region server at the specified address. 214 * @param serverName the region server to connect to 215 * @return proxy for HRegionServer 216 * @throws IOException if a remote or network exception occurs 217 */ 218 AdminService.BlockingInterface getAdmin(final ServerName serverName) throws IOException; 219 220 /** 221 * Establishes a connection to the region server at the specified address, and returns a region 222 * client protocol. 223 * @param serverName the region server to connect to 224 * @return ClientProtocol proxy for RegionServer 225 * @throws IOException if a remote or network exception occurs 226 */ 227 ClientService.BlockingInterface getClient(final ServerName serverName) throws IOException; 228 229 /** 230 * Find region location hosting passed row 231 * @param tableName table name 232 * @param row Row to find. 233 * @param reload If true do not use cache, otherwise bypass. 234 * @return Location of row. 235 * @throws IOException if a remote or network exception occurs 236 */ 237 HRegionLocation getRegionLocation(TableName tableName, byte[] row, boolean reload) 238 throws IOException; 239 240 /** 241 * Clear any caches that pertain to server name <code>sn</code>. 242 * @param sn A server name 243 */ 244 void clearCaches(final ServerName sn); 245 246 /** 247 * Returns Nonce generator for this ClusterConnection; may be null if disabled in configuration. 248 */ 249 NonceGenerator getNonceGenerator(); 250 251 /** Returns Default AsyncProcess associated with this connection. */ 252 AsyncProcess getAsyncProcess(); 253 254 /** 255 * Returns a new RpcRetryingCallerFactory from the given {@link Configuration}. This 256 * RpcRetryingCallerFactory lets the users create {@link RpcRetryingCaller}s which can be 257 * intercepted with the configured {@link RetryingCallerInterceptor} 258 * @param conf configuration 259 */ 260 RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf); 261 262 /** Returns Connection's RpcRetryingCallerFactory instance */ 263 RpcRetryingCallerFactory getRpcRetryingCallerFactory(); 264 265 /** Returns Connection's RpcControllerFactory instance */ 266 RpcControllerFactory getRpcControllerFactory(); 267 268 /** Returns a ConnectionConfiguration object holding parsed configuration values */ 269 ConnectionConfiguration getConnectionConfiguration(); 270 271 /** Returns the current statistics tracker associated with this connection */ 272 ServerStatisticTracker getStatisticsTracker(); 273 274 /** Returns the configured client backoff policy */ 275 ClientBackoffPolicy getBackoffPolicy(); 276 277 /** Returns the MetricsConnection instance associated with this connection. */ 278 MetricsConnection getConnectionMetrics(); 279 280 /** 281 * Returns true when this connection uses a {@link org.apache.hadoop.hbase.codec.Codec} and so 282 * supports cell blocks. 283 */ 284 boolean hasCellBlockSupport(); 285 286 /** 287 * Get live region servers from masters. 288 */ 289 List<ServerName> getLiveRegionServers(Supplier<ServerName> masterAddrTracker, int count) 290 throws IOException; 291 292 /** 293 * Get the bootstrap node list of another region server. 294 */ 295 List<ServerName> getAllBootstrapNodes(ServerName regionServer) throws IOException; 296 297 /** 298 * Get the {@link User} associated with this connection. May be {@code null}. 299 */ 300 User getUser(); 301 302 /** 303 * Get the {@link ConnectionRegistry} used to orient this cluster. 304 */ 305 ConnectionRegistry getConnectionRegistry(); 306}