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
AbstractRpcClient
to protect the fetching or creating connection. - There is a lock in
Call
to make sure that we can only finish the call once. - The same for
HBaseRpcController
asCall
. 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
Call
andHBaseRpcController
's lock should be held at last. So the callbacks inCall
andHBaseRpcController
should be execute outside the lock inCall
andHBaseRpcController
which means the implementations of the callbacks are free to hold any lock.
- Since:
- 2.0.0
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
static class
Blocking rpc channel that goes via hbase rpc.static class
Async rpc channel that goes via hbase rpc. -
Field Summary
Modifier and TypeFieldDescriptionprivate final AtomicInteger
protected final CellBlockBuilder
private final ScheduledFuture<?>
protected final String
protected final Codec
protected final org.apache.hadoop.io.compress.CompressionCodec
private static final org.apache.hbase.thirdparty.com.google.common.cache.LoadingCache<Address,
AtomicInteger> protected final org.apache.hadoop.conf.Configuration
private final PoolMap<ConnectionId,
T> protected final int
protected final FailedServers
protected final long
protected final boolean
private static final ScheduledExecutorService
protected final SocketAddress
static final org.slf4j.Logger
private int
protected final int
protected final MetricsConnection
protected final int
protected final int
private boolean
protected final boolean
protected final boolean
protected final UserProvider
protected static final org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer
protected final int
Fields 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
ConstructorDescriptionAbstractRpcClient
(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.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) Make a blocking call.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) void
Interrupt the connections to the given ip:port server.private void
void
close()
Stop all threads related to this client.protected abstract void
(package private) static HBaseRpcController
configureHBaseRpcController
(org.apache.hbase.thirdparty.com.google.protobuf.RpcController controller, int channelOperationTimeout) Configure an hbase rpccontroller(package private) static Address
createAddr
(ServerName sn) org.apache.hbase.thirdparty.com.google.protobuf.BlockingRpcChannel
createBlockingRpcChannel
(ServerName sn, User ticket, int rpcTimeout) Creates a "channel" that can be used by a blocking protobuf service.protected abstract T
createConnection
(ConnectionId remoteId) Not connected.org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel
createRpcChannel
(ServerName sn, User user, int rpcTimeout) Creates a "channel" that can be used by a protobuf service.protected Codec
getCodec()
Encapsulate the ugly casting and RuntimeException conversion in private method.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.private T
getConnection
(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 String
getDefaultCodec
(org.apache.hadoop.conf.Configuration c) private static int
getPoolSize
(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.PoolType
getPoolType
(org.apache.hadoop.conf.Configuration config) Return the pool type specified in the configuration, which must be set to eitherPoolMap.PoolType.RoundRobin
orPoolMap.PoolType.ThreadLocal
, otherwise default to the former.boolean
Return true when this client uses aCodec
and so supports cell blocks.protected boolean
private int
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)
-
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:RpcClient
Return true when this client uses aCodec
and so supports cell blocks.- Specified by:
hasCellBlockSupport
in 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.RoundRobin
orPoolMap.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 ofRpcClient
instances should not exceed the operating system's hard limit on the number of connections.- Parameters:
config
- configuration- Returns:
- either a
PoolMap.PoolType.RoundRobin
orPoolMap.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:
cancelConnections
in 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:RpcClient
Stop 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:RpcClient
Creates a "channel" that can be used by a blocking protobuf service. Useful setting up protobuf blocking stubs.- Specified by:
createBlockingRpcChannel
in 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:RpcClient
Creates a "channel" that can be used by a protobuf service. Useful setting up protobuf stubs.- Specified by:
createRpcChannel
in 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
-