org.apache.hadoop.hbase.ipc
Class HBaseClient

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

@InterfaceAudience.Private
public class HBaseClient
extends Object

A client for an IPC service. IPC calls take a single Protobuf message as a request and returns a single Protobuf message as result. A service runs on a port and is defined by a parameter class and a value class.

See HBaseServer


Nested Class Summary
protected  class HBaseClient.Call
          A call waiting for a value.
static class HBaseClient.CallTimeoutException
          Client-side call timeout
protected  class HBaseClient.Connection
          Thread that reads responses and notifies callers.
protected static class HBaseClient.ConnectionId
          This class holds the address and the user ticket.
static class HBaseClient.FailedServerException
           
 
Field Summary
protected  String clusterId
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  PoolMap<HBaseClient.ConnectionId,HBaseClient.Connection> connections
           
protected  int counter
           
static int FAILED_SERVER_EXPIRY_DEFAULT
           
static String FAILED_SERVER_EXPIRY_KEY
           
protected  org.apache.hadoop.hbase.ipc.HBaseClient.FailedServers failedServers
           
protected  long failureSleep
           
static org.apache.commons.logging.Log LOG
           
protected  int maxIdleTime
           
protected  int maxRetries
           
protected  int pingInterval
           
protected  AtomicBoolean running
           
protected  SocketFactory socketFactory
           
protected  int socketTimeout
           
protected  boolean tcpKeepAlive
           
protected  boolean tcpNoDelay
           
protected static Map<String,org.apache.hadoop.security.token.TokenSelector<? extends org.apache.hadoop.security.token.TokenIdentifier>> tokenHandlers
           
 
Constructor Summary
HBaseClient(org.apache.hadoop.conf.Configuration conf, String clusterId)
          Construct an IPC client with the default SocketFactory
HBaseClient(org.apache.hadoop.conf.Configuration conf, String clusterId, SocketFactory factory)
          Construct an IPC client whose values are of the Message class.
 
Method Summary
 Pair<com.google.protobuf.Message,CellScanner> call(Method method, com.google.protobuf.Message param, CellScanner cells, InetSocketAddress addr, Class<? extends IpcProtocol> protocol, User ticket, int rpcTimeout)
          Make a call, passing param, to the IPC server running at address which is servicing the protocol protocol, with the ticket credentials, returning the value.
 void cancelConnections(String hostname, int port, IOException ioe)
          Interrupt the connections to the given ip:port server.
protected  HBaseClient.Connection createConnection(HBaseClient.ConnectionId remoteId, Codec codec, org.apache.hadoop.io.compress.CompressionCodec compressor)
          Creates a connection.
protected  HBaseClient.Connection getConnection(InetSocketAddress addr, Class<? extends IpcProtocol> protocol, User ticket, int rpcTimeout, HBaseClient.Call call, Codec codec, org.apache.hadoop.io.compress.CompressionCodec compressor)
           
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 void setPingInterval(org.apache.hadoop.conf.Configuration conf, int pingInterval)
          set the ping interval value in configuration
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<HBaseClient.ConnectionId,HBaseClient.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

socketTimeout

protected int socketTimeout

failedServers

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

socketFactory

protected final SocketFactory socketFactory

clusterId

protected String clusterId

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

tokenHandlers

protected static final Map<String,org.apache.hadoop.security.token.TokenSelector<? extends org.apache.hadoop.security.token.TokenIdentifier>> tokenHandlers
Constructor Detail

HBaseClient

public HBaseClient(org.apache.hadoop.conf.Configuration conf,
                   String clusterId,
                   SocketFactory factory)
Construct an IPC client whose values are of the Message class.

Parameters:
conf - configuration
factory - socket factory

HBaseClient

public HBaseClient(org.apache.hadoop.conf.Configuration conf,
                   String clusterId)
Construct an IPC client with the default SocketFactory

Parameters:
conf - configuration
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 HBaseClient.Connection createConnection(HBaseClient.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

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 HBaseClient 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.


call

public Pair<com.google.protobuf.Message,CellScanner> call(Method method,
                                                          com.google.protobuf.Message param,
                                                          CellScanner cells,
                                                          InetSocketAddress addr,
                                                          Class<? extends IpcProtocol> protocol,
                                                          User ticket,
                                                          int rpcTimeout)
                                                   throws InterruptedException,
                                                          IOException
Make a call, passing param, to the IPC server running at address which is servicing the protocol protocol, with the ticket credentials, returning the value. Throws exceptions if there are network problems or if the remote code threw an exception.

Parameters:
method -
param -
cells -
addr -
protocol -
ticket - Be careful which ticket you pass. A new user will mean a new Connection. User.getCurrent() makes a new instance of User each time so will be a new Connection each time.
rpcTimeout -
Returns:
A pair with the Message response and the Cell data (if any).
Throws:
InterruptedException
IOException

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 HBaseClient.Connection getConnection(InetSocketAddress addr,
                                               Class<? extends IpcProtocol> protocol,
                                               User ticket,
                                               int rpcTimeout,
                                               HBaseClient.Call call,
                                               Codec codec,
                                               org.apache.hadoop.io.compress.CompressionCodec compressor)
                                        throws IOException,
                                               InterruptedException
Throws:
IOException
InterruptedException


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.