Package org.apache.hadoop.hbase.ipc
Class AbstractRpcClient<T extends RpcConnection>
java.lang.Object
org.apache.hadoop.hbase.ipc.AbstractRpcClient<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,RpcClient
- Direct Known Subclasses:
BlockingRpcClient,NettyRpcClient
@Private
public abstract class AbstractRpcClient<T extends RpcConnection>
extends Object
implements RpcClient
Provides the basics for a RpcClient implementation like configuration and Logging.
Locking schema of the current IPC implementation
- There is a lock in
AbstractRpcClientto protect the fetching or creating connection. - There is a lock in
Callto make sure that we can only finish the call once. - The same for
HBaseRpcControllerasCall. And see the comment ofHBaseRpcController.notifyOnCancel(RpcCallback, HBaseRpcController.CancellationCallback)of how to deal with cancel. - For connection implementation, the construction of a connection should be as fast as possible because the creation is protected under a lock. Connect to remote side when needed. There is no forced locking schema for a connection implementation.
- For the locking order, the
CallandHBaseRpcController's lock should be held at last. So the callbacks inCallandHBaseRpcControllershould be execute outside the lock inCallandHBaseRpcControllerwhich means the implementations of the callbacks are free to hold any lock.
- Since:
- 2.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classstatic classBlocking rpc channel that goes via hbase rpc.static classAsync rpc channel that goes via hbase rpc. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprotected final CellBlockBuilderprivate final ScheduledFuture<?>protected final Stringprotected final Codecprotected final org.apache.hadoop.io.compress.CompressionCodecprivate static final org.apache.hbase.thirdparty.com.google.common.cache.LoadingCache<Address,AtomicInteger> protected final org.apache.hadoop.conf.Configurationprivate final PoolMap<ConnectionId,T> protected final intprotected final FailedServersprotected final longprotected final booleanprivate static final ScheduledExecutorServiceprotected final SocketAddressstatic final org.slf4j.Loggerprivate intprotected final intprotected final MetricsConnectionprotected final intprotected final intprivate booleanprotected final booleanprotected final booleanprotected final UserProviderprotected static final org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimerprotected final intFields inherited from interface org.apache.hadoop.hbase.ipc.RpcClient
DEFAULT_CODEC_CLASS, DEFAULT_SOCKET_TIMEOUT_CONNECT, DEFAULT_SOCKET_TIMEOUT_READ, DEFAULT_SOCKET_TIMEOUT_WRITE, FAILED_SERVER_EXPIRY_DEFAULT, FAILED_SERVER_EXPIRY_KEY, IDLE_TIME, IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT, IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, PING_CALL_ID, REGISTRY_PREAMBLE_HEADER, SECURITY_PREAMBLE_HEADER, SOCKET_TIMEOUT_CONNECT, SOCKET_TIMEOUT_READ, SOCKET_TIMEOUT_WRITE, SPECIFIC_WRITE_THREAD -
Constructor Summary
ConstructorsConstructorDescriptionAbstractRpcClient(org.apache.hadoop.conf.Configuration conf, String clusterId, SocketAddress localAddr, MetricsConnection metrics, Map<String, byte[]> connectionAttributes) Construct an IPC client for the clusterclusterId -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.hbase.thirdparty.com.google.protobuf.MessagecallBlockingMethod(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor md, HBaseRpcController hrc, org.apache.hbase.thirdparty.com.google.protobuf.Message param, org.apache.hbase.thirdparty.com.google.protobuf.Message returnType, User ticket, Address isa) Make a blocking call.private CallcallMethod(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor md, HBaseRpcController hrc, org.apache.hbase.thirdparty.com.google.protobuf.Message param, org.apache.hbase.thirdparty.com.google.protobuf.Message returnType, User ticket, Address addr, org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<org.apache.hbase.thirdparty.com.google.protobuf.Message> callback) voidInterrupt the connections to the given ip:port server.private voidvoidclose()Stop all threads related to this client.protected abstract void(package private) static HBaseRpcControllerconfigureHBaseRpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController controller, int channelOperationTimeout) Configure an hbase rpccontroller(package private) static AddresscreateAddr(ServerName sn) org.apache.hbase.thirdparty.com.google.protobuf.BlockingRpcChannelcreateBlockingRpcChannel(ServerName sn, User ticket, int rpcTimeout) Creates a "channel" that can be used by a blocking protobuf service.protected abstract TcreateConnection(ConnectionId remoteId) Not connected.org.apache.hbase.thirdparty.com.google.protobuf.RpcChannelcreateRpcChannel(ServerName sn, User user, int rpcTimeout) Creates a "channel" that can be used by a protobuf service.protected CodecgetCodec()Encapsulate the ugly casting and RuntimeException conversion in private method.private static org.apache.hadoop.io.compress.CompressionCodecgetCompressor(org.apache.hadoop.conf.Configuration conf) Encapsulate the ugly casting and RuntimeException conversion in private method.private TgetConnection(ConnectionId remoteId) Get a connection from the pool, or create a new one and add it to the pool.(package private) PoolMap<ConnectionId,T> static StringgetDefaultCodec(org.apache.hadoop.conf.Configuration c) private static intgetPoolSize(org.apache.hadoop.conf.Configuration config) Return the pool size specified in the configuration, which is applicable only if the pool type isPoolMap.PoolType.RoundRobin.private static PoolMap.PoolTypegetPoolType(org.apache.hadoop.conf.Configuration config) Return the pool type specified in the configuration, which must be set to eitherPoolMap.PoolType.RoundRobinorPoolMap.PoolType.ThreadLocal, otherwise default to the former.booleanReturn true when this client uses aCodecand so supports cell blocks.protected booleanprivate intprivate voidonCallFinished(Call call, HBaseRpcController hrc, Address addr, org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<org.apache.hbase.thirdparty.com.google.protobuf.Message> callback)
-
Field Details
-
LOG
-
WHEEL_TIMER
-
IDLE_CONN_SWEEPER
-
running
-
conf
-
connectionAttributes
-
clusterId
-
localAddr
-
metrics
-
userProvider
-
cellBlockBuilder
-
minIdleTimeBeforeClose
-
maxRetries
-
failureSleep
-
tcpNoDelay
-
tcpKeepAlive
-
codec
-
compressor
-
fallbackAllowed
-
failedServers
-
connectTO
-
readTO
-
writeTO
-
connections
-
callIdCnt
-
cleanupIdleConnectionTask
-
maxConcurrentCallsPerServer
-
concurrentCounterCache
private static final org.apache.hbase.thirdparty.com.google.common.cache.LoadingCache<Address,AtomicInteger> concurrentCounterCache
-
-
Constructor Details
-
AbstractRpcClient
public AbstractRpcClient(org.apache.hadoop.conf.Configuration conf, String clusterId, SocketAddress localAddr, MetricsConnection metrics, Map<String, byte[]> connectionAttributes) Construct an IPC client for the clusterclusterId- Parameters:
conf- configurationclusterId- the cluster idlocalAddr- client socket bind address.metrics- the connection metrics
-
-
Method Details
-
cleanupIdleConnections
-
getDefaultCodec
-
getCodec
Encapsulate the ugly casting and RuntimeException conversion in private method.- Returns:
- Codec to use on this client.
-
hasCellBlockSupport
Description copied from interface:RpcClientReturn true when this client uses aCodecand so supports cell blocks.- Specified by:
hasCellBlockSupportin interfaceRpcClient
-
isTcpNoDelay
-
getCompressor
private static org.apache.hadoop.io.compress.CompressionCodec getCompressor(org.apache.hadoop.conf.Configuration conf) Encapsulate the ugly casting and RuntimeException conversion in private method.- Parameters:
conf- configuration- Returns:
- The compressor to use on this client.
-
getPoolType
Return the pool type specified in the configuration, which must be set to eitherPoolMap.PoolType.RoundRobinorPoolMap.PoolType.ThreadLocal, otherwise default to the former. For applications with many user threads, use a small round-robin pool. For applications with few user threads, you may want to try using a thread-local pool. In any case, the number ofRpcClientinstances should not exceed the operating system's hard limit on the number of connections.- Parameters:
config- configuration- Returns:
- either a
PoolMap.PoolType.RoundRobinorPoolMap.PoolType.ThreadLocal
-
getPoolSize
Return the pool size specified in the configuration, which is applicable only if the pool type isPoolMap.PoolType.RoundRobin.- Parameters:
config- configuration- Returns:
- the maximum pool size
-
nextCallId
-
callBlockingMethod
private org.apache.hbase.thirdparty.com.google.protobuf.Message callBlockingMethod(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor md, HBaseRpcController hrc, org.apache.hbase.thirdparty.com.google.protobuf.Message param, org.apache.hbase.thirdparty.com.google.protobuf.Message returnType, User ticket, Address isa) throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException Make a blocking call. Throws exceptions if there are network problems or if the remote code threw an exception.- Parameters:
ticket- Be careful which ticket you pass. A new user will mean a new Connection.UserProvider.getCurrent()makes a new instance of User each time so will be a new Connection each time.- Returns:
- A pair with the Message response and the Cell data (if any).
- Throws:
org.apache.hbase.thirdparty.com.google.protobuf.ServiceException
-
getConnection
Get a connection from the pool, or create a new one and add it to the pool. Connections to a given host/port are reused.- Throws:
IOException
-
createConnection
Not connected.- Throws:
IOException
-
onCallFinished
private void onCallFinished(Call call, HBaseRpcController hrc, Address addr, org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<org.apache.hbase.thirdparty.com.google.protobuf.Message> callback) -
callMethod
private Call callMethod(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor md, HBaseRpcController hrc, org.apache.hbase.thirdparty.com.google.protobuf.Message param, org.apache.hbase.thirdparty.com.google.protobuf.Message returnType, User ticket, Address addr, org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<org.apache.hbase.thirdparty.com.google.protobuf.Message> callback) -
createAddr
-
cancelConnections
Interrupt the connections to the given ip:port server. This should be called if the server is known as actually dead. This will not prevent current operation to be retried, and, depending on their own behavior, they may retry on the same server. This can be a feature, for example at startup. In any case, they're likely to get connection refused (if the process died) or no route to host: i.e. their next retries should be faster and with a safe exception.- Specified by:
cancelConnectionsin interfaceRpcClient- Parameters:
sn- server location to cancel connections of
-
configureHBaseRpcController
static HBaseRpcController configureHBaseRpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController controller, int channelOperationTimeout) Configure an hbase rpccontroller- Parameters:
controller- to configurechannelOperationTimeout- timeout for operation- Returns:
- configured controller
-
closeInternal
-
close
Description copied from interface:RpcClientStop all threads related to this client. No further calls may be made using this client. -
createBlockingRpcChannel
public org.apache.hbase.thirdparty.com.google.protobuf.BlockingRpcChannel createBlockingRpcChannel(ServerName sn, User ticket, int rpcTimeout) Description copied from interface:RpcClientCreates a "channel" that can be used by a blocking protobuf service. Useful setting up protobuf blocking stubs.- Specified by:
createBlockingRpcChannelin interfaceRpcClient- Parameters:
sn- server name describing location of serverticket- which is to use the connectionrpcTimeout- default rpc operation timeout- Returns:
- A blocking rpc channel that goes via this rpc client instance.
-
createRpcChannel
public org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel createRpcChannel(ServerName sn, User user, int rpcTimeout) Description copied from interface:RpcClientCreates a "channel" that can be used by a protobuf service. Useful setting up protobuf stubs.- Specified by:
createRpcChannelin interfaceRpcClient- Parameters:
sn- server name describing location of serveruser- which is to use the connectionrpcTimeout- default rpc operation timeout- Returns:
- A rpc channel that goes via this rpc client instance.
-
getConnections
-