org.apache.hadoop.hbase.ipc
Class RpcClient

java.lang.Object
  extended by org.apache.hadoop.hbase.ipc.RpcClient

@InterfaceAudience.Private
public class RpcClient
extends Object

Does RPC against a cluster. Manages connections per regionserver in the cluster.

See HBaseServer


Nested Class Summary
static class RpcClient.BlockingRpcChannelImplementation
          Blocking rpc channel that goes via hbase rpc.
protected  class RpcClient.Call
          A call waiting for a value.
static class RpcClient.CallTimeoutException
          Client-side call timeout
protected  class RpcClient.Connection
          Thread that reads responses and notifies callers.
protected static class RpcClient.ConnectionId
          This class holds the address and the user ticket, etc.
static class RpcClient.FailedServerException
           
 
Field Summary
protected  String clusterId
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  PoolMap<RpcClient.ConnectionId,RpcClient.Connection> connections
           
protected  int counter
           
static int FAILED_SERVER_EXPIRY_DEFAULT
           
static String FAILED_SERVER_EXPIRY_KEY
           
protected  org.apache.hadoop.hbase.ipc.RpcClient.FailedServers failedServers
           
protected  long failureSleep
           
static boolean IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT
           
static String IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY
           
protected  SocketAddress localAddr
           
static org.apache.commons.logging.Log LOG
           
protected  int maxIdleTime
           
protected  int maxRetries
           
protected  MetricsConnection metrics
           
static String PING_INTERVAL_NAME
           
protected  int pingInterval
           
protected  AtomicBoolean running
           
static String SOCKET_TIMEOUT
           
protected  SocketFactory socketFactory
           
protected  boolean tcpKeepAlive
           
protected  boolean tcpNoDelay
           
protected static Map<org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos.TokenIdentifier.Kind,org.apache.hadoop.security.token.TokenSelector<? extends org.apache.hadoop.security.token.TokenIdentifier>> tokenHandlers
           
 
Constructor Summary
RpcClient(org.apache.hadoop.conf.Configuration conf, String clusterId)
          Helper method for tests only.
RpcClient(org.apache.hadoop.conf.Configuration conf, String clusterId, MetricsConnection metrics)
          Construct an IPC client for the cluster clusterId with the default SocketFactory
RpcClient(org.apache.hadoop.conf.Configuration conf, String clusterId, SocketAddress localAddr, MetricsConnection metrics)
          Construct an IPC client for the cluster clusterId with the default SocketFactory
 
Method Summary
 void cancelConnections(String hostname, int port, IOException ioe)
          Interrupt the connections to the given ip:port server.
 com.google.protobuf.BlockingRpcChannel createBlockingRpcChannel(ServerName sn, User ticket, int rpcTimeout)
          Creates a "channel" that can be used by a blocking protobuf service.
protected  RpcClient.Connection createConnection(RpcClient.ConnectionId remoteId, Codec codec, org.apache.hadoop.io.compress.CompressionCodec compressor)
          Creates a connection.
protected  RpcClient.Connection getConnection(User ticket, RpcClient.Call call, InetSocketAddress addr, int rpcTimeout, Codec codec, org.apache.hadoop.io.compress.CompressionCodec compressor)
           
static String getDefaultCodec(org.apache.hadoop.conf.Configuration c)
           
protected 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 is PoolMap.PoolType.RoundRobin.
protected static PoolMap.PoolType getPoolType(org.apache.hadoop.conf.Configuration config)
          Return the pool type specified in the configuration, which must be set to either PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal, otherwise default to the former.
static int getRpcTimeout()
           
static int getRpcTimeout(int defaultTimeout)
          Returns the lower of the thread-local RPC time from setRpcTimeout(int) and the given default timeout.
static void resetRpcTimeout()
           
static void setPingInterval(org.apache.hadoop.conf.Configuration conf, int pingInterval)
          set the ping interval value in configuration
static void setRpcTimeout(int t)
           
static void setSocketTimeout(org.apache.hadoop.conf.Configuration conf, int socketTimeout)
          Set the socket timeout
 void stop()
          Stop all threads related to this client.
protected  IOException wrapException(InetSocketAddress addr, IOException exception)
          Take an IOException and the address we were trying to connect to and return an IOException with the input exception as the cause.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

connections

protected final PoolMap<RpcClient.ConnectionId,RpcClient.Connection> connections

counter

protected int counter

running

protected final AtomicBoolean running

conf

protected final org.apache.hadoop.conf.Configuration conf

maxIdleTime

protected final int maxIdleTime

maxRetries

protected final int maxRetries

failureSleep

protected final long failureSleep

tcpNoDelay

protected final boolean tcpNoDelay

tcpKeepAlive

protected final boolean tcpKeepAlive

pingInterval

protected int pingInterval

failedServers

protected org.apache.hadoop.hbase.ipc.RpcClient.FailedServers failedServers

socketFactory

protected final SocketFactory socketFactory

clusterId

protected String clusterId

localAddr

protected final SocketAddress localAddr

metrics

protected final MetricsConnection metrics

PING_INTERVAL_NAME

public static final String PING_INTERVAL_NAME
See Also:
Constant Field Values

SOCKET_TIMEOUT

public static final String SOCKET_TIMEOUT
See Also:
Constant Field Values

FAILED_SERVER_EXPIRY_KEY

public static final String FAILED_SERVER_EXPIRY_KEY
See Also:
Constant Field Values

FAILED_SERVER_EXPIRY_DEFAULT

public static final int FAILED_SERVER_EXPIRY_DEFAULT
See Also:
Constant Field Values

IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY

public static final String IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY
See Also:
Constant Field Values

IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT

public static final boolean IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT
See Also:
Constant Field Values

tokenHandlers

protected static final Map<org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos.TokenIdentifier.Kind,org.apache.hadoop.security.token.TokenSelector<? extends org.apache.hadoop.security.token.TokenIdentifier>> tokenHandlers
Constructor Detail

RpcClient

public RpcClient(org.apache.hadoop.conf.Configuration conf,
                 String clusterId)
Helper method for tests only. Creates an RpcClient without metrics.


RpcClient

public RpcClient(org.apache.hadoop.conf.Configuration conf,
                 String clusterId,
                 MetricsConnection metrics)
Construct an IPC client for the cluster clusterId with the default SocketFactory

Parameters:
conf - configuration
clusterId -

RpcClient

public RpcClient(org.apache.hadoop.conf.Configuration conf,
                 String clusterId,
                 SocketAddress localAddr,
                 MetricsConnection metrics)
Construct an IPC client for the cluster clusterId with the default SocketFactory

Parameters:
conf - configuration
clusterId -
localAddr - client socket bind address.
Method Detail

setPingInterval

public static void setPingInterval(org.apache.hadoop.conf.Configuration conf,
                                   int pingInterval)
set the ping interval value in configuration

Parameters:
conf - Configuration
pingInterval - the ping interval

setSocketTimeout

public static void setSocketTimeout(org.apache.hadoop.conf.Configuration conf,
                                    int socketTimeout)
Set the socket timeout

Parameters:
conf - Configuration
socketTimeout - the socket timeout

createConnection

protected RpcClient.Connection createConnection(RpcClient.ConnectionId remoteId,
                                                Codec codec,
                                                org.apache.hadoop.io.compress.CompressionCodec compressor)
                                         throws IOException
Creates a connection. Can be overridden by a subclass for testing.

Parameters:
remoteId - - the ConnectionId to use for the connection creation.
Throws:
IOException

getDefaultCodec

public static String getDefaultCodec(org.apache.hadoop.conf.Configuration c)

getPoolType

protected static PoolMap.PoolType getPoolType(org.apache.hadoop.conf.Configuration config)
Return the pool type specified in the configuration, which must be set to either PoolMap.PoolType.RoundRobin or PoolMap.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 of RpcClient instances should not exceed the operating system's hard limit on the number of connections.

Parameters:
config - configuration
Returns:
either a PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal

getPoolSize

protected 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 is PoolMap.PoolType.RoundRobin.

Parameters:
config -
Returns:
the maximum pool size

stop

public void stop()
Stop all threads related to this client. No further calls may be made using this client.


wrapException

protected IOException wrapException(InetSocketAddress addr,
                                    IOException exception)
Take an IOException and the address we were trying to connect to and return an IOException with the input exception as the cause. The new exception provides the stack trace of the place where the exception is thrown and some extra diagnostics information. If the exception is ConnectException or SocketTimeoutException, return a new one of the same type; Otherwise return an IOException.

Parameters:
addr - target address
exception - the relevant exception
Returns:
an exception to throw

cancelConnections

public void cancelConnections(String hostname,
                              int port,
                              IOException ioe)
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. there next retries should be faster and with a safe exception.


getConnection

protected RpcClient.Connection getConnection(User ticket,
                                             RpcClient.Call call,
                                             InetSocketAddress addr,
                                             int rpcTimeout,
                                             Codec codec,
                                             org.apache.hadoop.io.compress.CompressionCodec compressor)
                                      throws IOException,
                                             InterruptedException
Throws:
IOException
InterruptedException

setRpcTimeout

public static void setRpcTimeout(int t)

getRpcTimeout

public static int getRpcTimeout()

getRpcTimeout

public static int getRpcTimeout(int defaultTimeout)
Returns the lower of the thread-local RPC time from setRpcTimeout(int) and the given default timeout.


resetRpcTimeout

public static void resetRpcTimeout()

createBlockingRpcChannel

public com.google.protobuf.BlockingRpcChannel createBlockingRpcChannel(ServerName sn,
                                                                       User ticket,
                                                                       int rpcTimeout)
Creates a "channel" that can be used by a blocking protobuf service. Useful setting up protobuf blocking stubs.

Parameters:
sn -
ticket -
rpcTimeout -
Returns:
A blocking rpc channel that goes via this rpc client instance.


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.