@InterfaceAudience.LimitedPrivate(value={"Coprocesssor","Phoenix"}) @InterfaceStability.Evolving public class RpcServer extends Object implements RpcServerInterface, ConfigurationObserver
Scheduler can be variously implemented but default simple scheduler has handlers to which it has given the queues into which calls (i.e. CallRunner instances) are inserted. Handlers run taking from the queue. They run the CallRunner#run method on each item gotten from queue and keep taking while the server is up. CallRunner#run executes the call. When done, asks the included Call to put itself on new queue for Responder to pull from and return result to client.
RpcClientImpl
Modifier and Type | Class and Description |
---|---|
static class |
RpcServer.BlockingServiceAndInterface
Datastructure for passing a
BlockingService and its associated class of
protobuf service interface. |
class |
RpcServer.Call
Datastructure that holds all necessary to a method invocation and then afterward, carries
the result.
|
class |
RpcServer.Connection
Reads calls from a connection and queues them for handling.
|
private class |
RpcServer.Listener
Listens on the socket.
|
protected class |
RpcServer.Responder |
Modifier and Type | Field and Description |
---|---|
protected InetSocketAddress |
address |
private boolean |
allowFallbackToSimpleAuth |
private static org.apache.commons.logging.Log |
AUDITLOG |
private static String |
AUTH_FAILED_FOR |
private static String |
AUTH_SUCCESSFUL_FOR |
protected org.apache.hadoop.security.authorize.ServiceAuthorizationManager |
authManager |
private boolean |
authorize |
protected AuthenticationTokenSecretManager |
authTokenSecretMgr |
protected InetSocketAddress |
bindAddress |
private static CallQueueTooBigException |
CALL_QUEUE_TOO_BIG_EXCEPTION |
protected Counter |
callQueueSize
This is a running count of the size of all outstanding calls by size.
|
protected org.apache.hadoop.conf.Configuration |
conf |
protected List<RpcServer.Connection> |
connectionList |
protected static ThreadLocal<RpcServer.Call> |
CurCall
This is set to Call object before Handler invokes an RPC and ybdie
after the call returns.
|
static byte |
CURRENT_VERSION |
(package private) static int |
DEFAULT_MAX_CALLQUEUE_LENGTH_PER_HANDLER
How many calls/handler are allowed in the queue.
|
private static int |
DEFAULT_MAX_CALLQUEUE_SIZE
The maximum size that we can hold in the RPC queue
|
private static int |
DEFAULT_WARN_RESPONSE_SIZE |
private static int |
DEFAULT_WARN_RESPONSE_TIME
Default value for above params
|
protected HBaseRPCErrorHandler |
errorHandler |
static String |
FALLBACK_TO_INSECURE_CLIENT_AUTH
Whether we allow a fallback to SIMPLE auth for insecure clients when security is enabled.
|
private IPCUtil |
ipcUtil |
private boolean |
isSecurityEnabled |
private RpcServer.Listener |
listener |
static org.apache.commons.logging.Log |
LOG |
private static org.codehaus.jackson.map.ObjectMapper |
MAPPER |
(package private) int |
maxConnectionsToNuke |
protected int |
maxIdleTime |
private int |
maxQueueSize |
protected MetricsHBaseServer |
metrics |
(package private) static ThreadLocal<MonitoredRPCHandler> |
MONITORED_RPC
Keeps MonitoredRPCHandler per handler thread.
|
private static int |
NIO_BUFFER_LIMIT
When the read or write buffer size is larger than this limit, i/o will be
done in chunks of this size.
|
protected int |
numConnections |
protected int |
port |
protected long |
purgeTimeout |
private int |
readThreads |
private BoundedByteBufferPool |
reservoir |
protected RpcServer.Responder |
responder |
private RSRpcServices |
rsRpcServices
Used to get details for scan with a scanner_id
TODO try to figure out a better way and remove reference from regionserver package later. |
(package private) boolean |
running
This flag is used to indicate to sub threads when they should go down.
|
private RpcScheduler |
scheduler |
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> |
secretManager |
private Server |
server |
private List<RpcServer.BlockingServiceAndInterface> |
services |
protected int |
socketSendBufferSize |
(package private) boolean |
started
This flag is set to true after all threads are up and 'running' and the server is then opened
for business by the call to
start() . |
protected boolean |
tcpKeepAlive |
protected boolean |
tcpNoDelay |
protected int |
thresholdIdleConnections |
private UserProvider |
userProvider |
private static String |
WARN_RESPONSE_SIZE |
private static String |
WARN_RESPONSE_TIME |
private int |
warnResponseSize |
private int |
warnResponseTime |
Constructor and Description |
---|
RpcServer(Server server,
String name,
List<RpcServer.BlockingServiceAndInterface> services,
InetSocketAddress bindAddress,
org.apache.hadoop.conf.Configuration conf,
RpcScheduler scheduler)
Constructs a server listening on the named port and address.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallSize(long diff)
Add/subtract from the current size of all outstanding calls.
|
void |
authorize(org.apache.hadoop.security.UserGroupInformation user,
org.apache.hadoop.hbase.protobuf.generated.RPCProtos.ConnectionHeader connection,
InetAddress addr)
Authorize the incoming client connection.
|
static void |
bind(ServerSocket socket,
InetSocketAddress address,
int backlog)
A convenience method to bind to a given address and report
better exceptions if the address is not a valid host.
|
Pair<com.google.protobuf.Message,CellScanner> |
call(com.google.protobuf.BlockingService service,
com.google.protobuf.Descriptors.MethodDescriptor md,
com.google.protobuf.Message param,
CellScanner cellScanner,
long receiveTime,
MonitoredRPCHandler status)
This is a server side method, which is invoked over RPC.
|
private static int |
channelIO(ReadableByteChannel readCh,
WritableByteChannel writeCh,
ByteBuffer buf)
|
protected int |
channelRead(ReadableByteChannel channel,
ByteBuffer buffer)
This is a wrapper around
ReadableByteChannel.read(java.nio.ByteBuffer) . |
protected long |
channelWrite(GatheringByteChannel channel,
BufferChain bufferChain)
This is a wrapper around
WritableByteChannel.write(java.nio.ByteBuffer) . |
protected void |
closeConnection(RpcServer.Connection connection) |
private AuthenticationTokenSecretManager |
createSecretManager() |
(package private) org.apache.hadoop.conf.Configuration |
getConf() |
protected RpcServer.Connection |
getConnection(SocketChannel channel,
long time)
Subclasses of HBaseServer can override this to provide their own
Connection implementations.
|
static RpcCallContext |
getCurrentCall()
Needed for features such as delayed calls.
|
HBaseRPCErrorHandler |
getErrorHandler() |
InetSocketAddress |
getListenerAddress()
Return the socket (ip+port) on which the RPC server is listening to.
|
MetricsHBaseServer |
getMetrics()
Returns the metrics instance for reporting RPC call statistics
|
static InetAddress |
getRemoteAddress() |
static InetAddress |
getRemoteIp()
Returns the remote side ip address when invoked inside an RPC
Returns null incase of an error.
|
static User |
getRequestUser()
Returns the user credentials associated with the current RPC request or
null if no credentials were provided. |
static String |
getRequestUserName()
Returns the username for any user associated with the current RPC
request or
null if no user is set. |
RpcScheduler |
getScheduler() |
org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> |
getSecretManager() |
(package private) static com.google.protobuf.BlockingService |
getService(List<RpcServer.BlockingServiceAndInterface> services,
String serviceName) |
(package private) static RpcServer.BlockingServiceAndInterface |
getServiceAndInterface(List<RpcServer.BlockingServiceAndInterface> services,
String serviceName) |
(package private) static Class<?> |
getServiceInterface(List<RpcServer.BlockingServiceAndInterface> services,
String serviceName) |
(package private) static MonitoredRPCHandler |
getStatus() |
private void |
initReconfigurable(org.apache.hadoop.conf.Configuration confToLoad) |
static boolean |
isInRpcCallContext() |
boolean |
isStarted() |
void |
join()
Wait for the server to be stopped.
|
(package private) void |
logResponse(com.google.protobuf.Message param,
String methodName,
String call,
String tag,
String clientAddress,
long startTime,
int processingTime,
int qTime,
long responseSize)
Logs an RPC response to the LOG file, producing valid JSON objects for
client Operations.
|
void |
onConfigurationChange(org.apache.hadoop.conf.Configuration newConf)
This method would be called by the
ConfigurationManager
object when the Configuration object is reloaded from disk. |
void |
refreshAuthManager(org.apache.hadoop.security.authorize.PolicyProvider pp)
Refresh authentication manager policy.
|
void |
setErrorHandler(HBaseRPCErrorHandler handler)
Set the handler for calling out of RPC for error conditions.
|
void |
setRsRpcServices(RSRpcServices rsRpcServices) |
void |
setSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager) |
void |
setSocketSendBufSize(int size)
Sets the socket buffer size used for responding to RPCs.
|
private void |
setupResponse(ByteArrayOutputStream response,
RpcServer.Call call,
Throwable t,
String error)
Setup response for the RPC Call.
|
void |
start()
Starts the service.
|
void |
stop()
Stops the service.
|
public static final org.apache.commons.logging.Log LOG
private static final CallQueueTooBigException CALL_QUEUE_TOO_BIG_EXCEPTION
private final boolean authorize
private boolean isSecurityEnabled
public static final byte CURRENT_VERSION
public static final String FALLBACK_TO_INSECURE_CLIENT_AUTH
static final int DEFAULT_MAX_CALLQUEUE_LENGTH_PER_HANDLER
private static final int DEFAULT_MAX_CALLQUEUE_SIZE
private final IPCUtil ipcUtil
private static final String AUTH_FAILED_FOR
private static final String AUTH_SUCCESSFUL_FOR
private static final org.apache.commons.logging.Log AUDITLOG
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> secretManager
protected org.apache.hadoop.security.authorize.ServiceAuthorizationManager authManager
protected static final ThreadLocal<RpcServer.Call> CurCall
static final ThreadLocal<MonitoredRPCHandler> MONITORED_RPC
protected final InetSocketAddress bindAddress
protected int port
protected InetSocketAddress address
private int readThreads
protected int maxIdleTime
protected int thresholdIdleConnections
int maxConnectionsToNuke
protected MetricsHBaseServer metrics
protected final org.apache.hadoop.conf.Configuration conf
private int maxQueueSize
protected int socketSendBufferSize
protected final boolean tcpNoDelay
protected final boolean tcpKeepAlive
protected final long purgeTimeout
volatile boolean running
volatile boolean started
start()
.protected final Counter callQueueSize
protected final List<RpcServer.Connection> connectionList
private RpcServer.Listener listener
protected RpcServer.Responder responder
protected AuthenticationTokenSecretManager authTokenSecretMgr
protected int numConnections
protected HBaseRPCErrorHandler errorHandler
private static final String WARN_RESPONSE_TIME
private static final String WARN_RESPONSE_SIZE
private static final int DEFAULT_WARN_RESPONSE_TIME
private static final int DEFAULT_WARN_RESPONSE_SIZE
private static final org.codehaus.jackson.map.ObjectMapper MAPPER
private final int warnResponseTime
private final int warnResponseSize
private final Server server
private final List<RpcServer.BlockingServiceAndInterface> services
private final RpcScheduler scheduler
private UserProvider userProvider
private final BoundedByteBufferPool reservoir
private volatile boolean allowFallbackToSimpleAuth
private RSRpcServices rsRpcServices
private static int NIO_BUFFER_LIMIT
public RpcServer(Server server, String name, List<RpcServer.BlockingServiceAndInterface> services, InetSocketAddress bindAddress, org.apache.hadoop.conf.Configuration conf, RpcScheduler scheduler) throws IOException
server
- hosting instance of Server
. We will do authentications if an
instance else pass null for no authentication check.name
- Used keying this rpc servers' metrics and for naming the Listener thread.services
- A list of services.bindAddress
- Where to listenconf
- scheduler
- IOException
public void onConfigurationChange(org.apache.hadoop.conf.Configuration newConf)
ConfigurationObserver
ConfigurationManager
object when the Configuration
object is reloaded from disk.onConfigurationChange
in interface ConfigurationObserver
private void initReconfigurable(org.apache.hadoop.conf.Configuration confToLoad)
protected RpcServer.Connection getConnection(SocketChannel channel, long time)
private void setupResponse(ByteArrayOutputStream response, RpcServer.Call call, Throwable t, String error) throws IOException
response
- buffer to serialize the response intocall
- RpcServer.Call
to which we are setting up the responseerror
- error message, if the call failedIOException
protected void closeConnection(RpcServer.Connection connection)
org.apache.hadoop.conf.Configuration getConf()
public void setSocketSendBufSize(int size)
setSocketSendBufSize
in interface RpcServerInterface
size
- send sizepublic boolean isStarted()
isStarted
in interface RpcServerInterface
public void start()
start
in interface RpcServerInterface
public void refreshAuthManager(org.apache.hadoop.security.authorize.PolicyProvider pp)
RpcServerInterface
refreshAuthManager
in interface RpcServerInterface
private AuthenticationTokenSecretManager createSecretManager()
public org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> getSecretManager()
public void setSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager)
public Pair<com.google.protobuf.Message,CellScanner> call(com.google.protobuf.BlockingService service, com.google.protobuf.Descriptors.MethodDescriptor md, com.google.protobuf.Message param, CellScanner cellScanner, long receiveTime, MonitoredRPCHandler status) throws IOException
call
in interface RpcServerInterface
IOException
void logResponse(com.google.protobuf.Message param, String methodName, String call, String tag, String clientAddress, long startTime, int processingTime, int qTime, long responseSize) throws IOException
param
- The parameters received in the call.methodName
- The name of the method invokedcall
- The string representation of the calltag
- The tag that will be used to indicate this event in the log.clientAddress
- The address of the client who made this call.startTime
- The time that the call was initiated, in ms.processingTime
- The duration that the call took to run, in ms.qTime
- The duration that the call spent on the queue
prior to being initiated, in ms.responseSize
- The size in bytes of the response buffer.IOException
public void stop()
stop
in interface RpcServerInterface
public void join() throws InterruptedException
stop()
.join
in interface RpcServerInterface
InterruptedException
- epublic InetSocketAddress getListenerAddress()
getListenerAddress
in interface RpcServerInterface
public void setErrorHandler(HBaseRPCErrorHandler handler)
setErrorHandler
in interface RpcServerInterface
handler
- the handler implementationpublic HBaseRPCErrorHandler getErrorHandler()
getErrorHandler
in interface RpcServerInterface
public MetricsHBaseServer getMetrics()
getMetrics
in interface RpcServerInterface
public void addCallSize(long diff)
RpcServerInterface
addCallSize
in interface RpcServerInterface
diff
- Change (plus or minus)public void authorize(org.apache.hadoop.security.UserGroupInformation user, org.apache.hadoop.hbase.protobuf.generated.RPCProtos.ConnectionHeader connection, InetAddress addr) throws org.apache.hadoop.security.authorize.AuthorizationException
user
- client userconnection
- incoming connectionaddr
- InetAddress of incoming connectionorg.apache.hadoop.security.authorize.AuthorizationException
- when the client isn't authorized to talk the protocolprotected long channelWrite(GatheringByteChannel channel, BufferChain bufferChain) throws IOException
WritableByteChannel.write(java.nio.ByteBuffer)
.
If the amount of data is large, it writes to channel in smaller chunks.
This is to avoid jdk from creating many direct buffers as the size of
buffer increases. This also minimizes extra copies in NIO layer
as a result of multiple write operations required to write a large
buffer.channel
- writable byte channel to write tobufferChain
- Chain of buffers to writeIOException
- eWritableByteChannel.write(java.nio.ByteBuffer)
protected int channelRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOException
ReadableByteChannel.read(java.nio.ByteBuffer)
.
If the amount of data is large, it writes to channel in smaller chunks.
This is to avoid jdk from creating many direct buffers as the size of
ByteBuffer increases. There should not be any performance degredation.channel
- writable byte channel to write onbuffer
- buffer to writeIOException
- eReadableByteChannel.read(java.nio.ByteBuffer)
private static int channelIO(ReadableByteChannel readCh, WritableByteChannel writeCh, ByteBuffer buf) throws IOException
channelRead(java.nio.channels.ReadableByteChannel, java.nio.ByteBuffer)
and channelWrite(GatheringByteChannel, BufferChain)
. Only
one of readCh or writeCh should be non-null.readCh
- read channelwriteCh
- write channelbuf
- buffer to read or write into/out ofIOException
- echannelRead(java.nio.channels.ReadableByteChannel, java.nio.ByteBuffer)
,
channelWrite(GatheringByteChannel, BufferChain)
public static RpcCallContext getCurrentCall()
public static boolean isInRpcCallContext()
public static User getRequestUser()
null
if no credentials were provided.public static String getRequestUserName()
null
if no user is set.public static InetAddress getRemoteAddress()
static RpcServer.BlockingServiceAndInterface getServiceAndInterface(List<RpcServer.BlockingServiceAndInterface> services, String serviceName)
serviceName
- Some arbitrary string that represents a 'service'.services
- Available service instancesstatic Class<?> getServiceInterface(List<RpcServer.BlockingServiceAndInterface> services, String serviceName)
serviceName
- Some arbitrary string that represents a 'service'.services
- Available services and their service interfaces.serviceName
static com.google.protobuf.BlockingService getService(List<RpcServer.BlockingServiceAndInterface> services, String serviceName)
serviceName
- Some arbitrary string that represents a 'service'.services
- Available services and their service interfaces.serviceName
static MonitoredRPCHandler getStatus()
public static InetAddress getRemoteIp()
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException
socket
- the socket to bindaddress
- the address to bind tobacklog
- the number of connections allowed in the queueBindException
- if the address can't be boundUnknownHostException
- if the address isn't a valid host nameIOException
- other random errors from bindpublic RpcScheduler getScheduler()
getScheduler
in interface RpcServerInterface
public void setRsRpcServices(RSRpcServices rsRpcServices)
setRsRpcServices
in interface RpcServerInterface
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.