Package org.apache.hadoop.hbase.ipc
Class RpcServer
java.lang.Object
org.apache.hadoop.hbase.ipc.RpcServer
- All Implemented Interfaces:
ConfigurationObserver
,RpcServerInterface
- Direct Known Subclasses:
NettyRpcServer
,SimpleRpcServer
@Private
public abstract class RpcServer
extends Object
implements RpcServerInterface, ConfigurationObserver
An RPC server that hosts protobuf described Services.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Datastructure for passing aBlockingService
and its associated class of protobuf service interface.protected static interface
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected static final org.slf4j.Logger
protected static final String
protected static final String
protected org.apache.hadoop.security.authorize.ServiceAuthorizationManager
private final boolean
protected AuthenticationTokenSecretManager
protected final ByteBuffAllocator
protected final InetSocketAddress
protected static final CallQueueTooBigException
protected final LongAdder
This is a running count of the size in bytes of all outstanding calls whether currently executing or queued waiting to be run.protected final CellBlockBuilder
protected final org.apache.hadoop.conf.Configuration
protected static final ThreadLocal<RpcCall>
This is set to Call object before Handler invokes an RPC and ybdie after the call returns.static final byte
protected static final int
How many calls/handler are allowed in the queue.protected static final int
static final int
Default value for above paramsprotected static final int
protected static final int
protected static final int
protected static final int
protected HBaseRPCErrorHandler
static final String
Whether we allow a fallback to SIMPLE auth for insecure clients when security is enabled.protected static final org.apache.hbase.thirdparty.com.google.gson.Gson
private boolean
protected boolean
protected static final String
static final org.slf4j.Logger
static final String
protected final long
Maximum size in bytes of the currently queued and running Calls.protected final int
protected MetricsHBaseServer
protected static final String
Minimum allowable timeout (in milliseconds) in rpc request's header.protected final int
protected static final ThreadLocal<MonitoredRPCHandler>
Keeps MonitoredRPCHandler per handler thread.private static final String
private static final String
private static final String
private NamedQueueRecorder
Use to add online slowlog responsesprotected static final int
When the read or write buffer size is larger than this limit, i/o will be done in chunks of this size.private 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
This flag is used to indicate to sub threads when they should go down.protected final RpcScheduler
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier>
protected final Server
protected final String
protected final List<RpcServer.BlockingServiceAndInterface>
(package private) boolean
This flag is set to true after all threads are up and 'running' and the server is then opened for business by the call toRpcServerInterface.start()
.protected final boolean
protected final boolean
protected static final String
protected final UserProvider
protected static final String
protected static final String
protected static final String
protected static final String
protected int
protected int
protected int
protected int
-
Constructor Summary
ConstructorDescriptionRpcServer
(Server server, String name, List<RpcServer.BlockingServiceAndInterface> services, InetSocketAddress bindAddress, org.apache.hadoop.conf.Configuration conf, RpcScheduler scheduler, boolean reservoirEnabled) Constructs a server listening on the named port and address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.shaded.protobuf.generated.RPCProtos.ConnectionHeader connection, InetAddress addr) Authorize the incoming client connection.Pair<org.apache.hbase.thirdparty.com.google.protobuf.Message,
CellScanner> call
(RpcCall call, 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 aroundReadableByteChannel.read(java.nio.ByteBuffer)
.protected AuthenticationTokenSecretManager
Allocator to allocate/free the ByteBuffers, those ByteBuffers can be on-heap or off-heap.(package private) org.apache.hadoop.conf.Configuration
getConf()
Needed for features such as delayed calls.private static boolean
getIsOnlineLogProviderEnabled
(org.apache.hadoop.conf.Configuration conf) Returns the metrics instance for reporting RPC call statisticsabstract int
The number of open RPC conectionsstatic Optional<InetAddress>
Returns the address of the remote client associated with the current RPC request or not present if no address is set.static InetAddress
Returns the remote side ip address when invoked inside an RPC Returns null incase of an error.Returns the user credentials associated with the current RPC request or not present if no credentials were provided.Returns the username for any user associated with the current RPC request or not present if no user is set.org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier>
protected static org.apache.hbase.thirdparty.com.google.protobuf.BlockingService
getService
(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) protected static RpcServer.BlockingServiceAndInterface
getServiceAndInterface
(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) protected static Class<?>
getServiceInterface
(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) protected static MonitoredRPCHandler
private static int
getWarnResponseSize
(org.apache.hadoop.conf.Configuration conf) private static int
getWarnResponseTime
(org.apache.hadoop.conf.Configuration conf) private static int
getWarnScanResponseSize
(org.apache.hadoop.conf.Configuration conf) private static int
getWarnScanResponseTime
(org.apache.hadoop.conf.Configuration conf) protected void
initReconfigurable
(org.apache.hadoop.conf.Configuration confToLoad) static boolean
boolean
private boolean
isTooLarge
(RpcCall call, long responseSize, long responseBlockSize) private boolean
(package private) void
logResponse
(org.apache.hbase.thirdparty.com.google.protobuf.Message param, String methodName, String call, boolean tooLarge, boolean tooSlow, String clientAddress, long startTime, int processingTime, int qTime, long responseSize, long blockBytesScanned, long fsReadTime, String userName) Logs an RPC response to the LOG file, producing valid JSON objects for client Operations.protected boolean
void
onConfigurationChange
(org.apache.hadoop.conf.Configuration newConf) This method would be called by theConfigurationManager
object when theConfiguration
object is reloaded from disk.void
refreshAuthManager
(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider pp) Refresh authentication manager policy.private void
refreshSlowLogConfiguration
(org.apache.hadoop.conf.Configuration newConf) static void
setCurrentCall
(RpcCall rpcCall) Used byRegionProcedureStore
.void
setErrorHandler
(HBaseRPCErrorHandler handler) Set the handler for calling out of RPC for error conditions.void
setNamedQueueRecorder
(NamedQueueRecorder namedQueueRecorder) Set Online SlowLog Providervoid
setRsRpcServices
(RSRpcServices rsRpcServices) void
setSecretManager
(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager) (package private) String
truncateTraceLog
(String strParam) Truncate to number of chars decided by conf hbase.ipc.trace.log.max.length if TRACE is on else to 150 chars Refer to Jira HBASE-20826 and HBASE-20942Used byRegionProcedureStore
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.ipc.RpcServerInterface
call, call, getListenerAddress, join, setSocketSendBufSize, start, stop
-
Field Details
-
LOG
-
CALL_QUEUE_TOO_BIG_EXCEPTION
-
MULTI_GETS
- See Also:
-
MULTI_MUTATIONS
- See Also:
-
MULTI_SERVICE_CALLS
- See Also:
-
authorize
-
isOnlineLogProviderEnabled
-
isSecurityEnabled
-
CURRENT_VERSION
- See Also:
-
FALLBACK_TO_INSECURE_CLIENT_AUTH
Whether we allow a fallback to SIMPLE auth for insecure clients when security is enabled.- See Also:
-
DEFAULT_MAX_CALLQUEUE_LENGTH_PER_HANDLER
How many calls/handler are allowed in the queue.- See Also:
-
cellBlockBuilder
-
AUTH_FAILED_FOR
- See Also:
-
AUTH_SUCCESSFUL_FOR
- See Also:
-
AUDITLOG
-
secretManager
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> secretManager -
saslProps
-
serverPrincipal
-
authManager
-
CurCall
This is set to Call object before Handler invokes an RPC and ybdie after the call returns. -
MONITORED_RPC
Keeps MonitoredRPCHandler per handler thread. -
bindAddress
-
metrics
-
conf
-
maxQueueSizeInBytes
Maximum size in bytes of the currently queued and running Calls. If a new Call puts us over this size, then we will reject the call (after parsing it though). It will go back to the client and client will retry. Set this size with "hbase.ipc.server.max.callqueue.size". The call queue size gets incremented after we parse a call and before we add it to the queue of calls for the scheduler to use. It get decremented after we have 'run' the Call. The current size is kept incallQueueSizeInBytes
. -
DEFAULT_MAX_CALLQUEUE_SIZE
- See Also:
-
callQueueSizeInBytes
This is a running count of the size in bytes of all outstanding calls whether currently executing or queued waiting to be run. -
tcpNoDelay
-
tcpKeepAlive
-
running
This flag is used to indicate to sub threads when they should go down. When we callRpcServerInterface.start()
, all threads started will consult this flag on whether they should keep going. It is set to false whenRpcServerInterface.stop()
is called. -
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 toRpcServerInterface.start()
. -
authTokenSecretMgr
-
errorHandler
-
MAX_REQUEST_SIZE
- See Also:
-
WARN_RESPONSE_TIME
- See Also:
-
WARN_RESPONSE_SIZE
- See Also:
-
WARN_SCAN_RESPONSE_TIME
- See Also:
-
WARN_SCAN_RESPONSE_SIZE
- See Also:
-
MIN_CLIENT_REQUEST_TIMEOUT
Minimum allowable timeout (in milliseconds) in rpc request's header. This configuration exists to prevent the rpc service regarding this request as timeout immediately.- See Also:
-
DEFAULT_MIN_CLIENT_REQUEST_TIMEOUT
- See Also:
-
DEFAULT_MAX_REQUEST_SIZE
Default value for above params- See Also:
-
DEFAULT_WARN_RESPONSE_TIME
- See Also:
-
DEFAULT_WARN_RESPONSE_SIZE
- See Also:
-
DEFAULT_TRACE_LOG_MAX_LENGTH
- See Also:
-
TRACE_LOG_MAX_LENGTH
- See Also:
-
KEY_WORD_TRUNCATED
- See Also:
-
GSON
-
maxRequestSize
-
warnResponseTime
-
warnResponseSize
-
warnScanResponseTime
-
warnScanResponseSize
-
minClientRequestTimeout
-
server
-
services
-
scheduler
-
userProvider
-
bbAllocator
-
allowFallbackToSimpleAuth
-
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. -
namedQueueRecorder
Use to add online slowlog responses -
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. Most RPC requests and responses would be be smaller.- See Also:
-
-
Constructor Details
-
RpcServer
public RpcServer(Server server, String name, List<RpcServer.BlockingServiceAndInterface> services, InetSocketAddress bindAddress, org.apache.hadoop.conf.Configuration conf, RpcScheduler scheduler, boolean reservoirEnabled) throws IOException Constructs a server listening on the named port and address.- Parameters:
server
- hosting instance ofServer
. 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 listenreservoirEnabled
- Enable ByteBufferPool or not.- Throws:
IOException
-
-
Method Details
-
onConfigurationChange
Description copied from interface:ConfigurationObserver
This method would be called by theConfigurationManager
object when theConfiguration
object is reloaded from disk.- Specified by:
onConfigurationChange
in interfaceConfigurationObserver
-
refreshSlowLogConfiguration
-
getIsOnlineLogProviderEnabled
-
getWarnResponseTime
-
getWarnResponseSize
-
getWarnScanResponseTime
-
getWarnScanResponseSize
-
initReconfigurable
-
getConf
org.apache.hadoop.conf.Configuration getConf() -
isStarted
- Specified by:
isStarted
in interfaceRpcServerInterface
-
refreshAuthManager
public void refreshAuthManager(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider pp) Description copied from interface:RpcServerInterface
Refresh authentication manager policy.- Specified by:
refreshAuthManager
in interfaceRpcServerInterface
-
createSecretManager
-
getSecretManager
public org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> getSecretManager() -
setSecretManager
public void setSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager) -
call
public Pair<org.apache.hbase.thirdparty.com.google.protobuf.Message,CellScanner> call(RpcCall call, MonitoredRPCHandler status) throws IOException This is a server side method, which is invoked over RPC. On success the return response has protobuf response payload. On failure, the exception name and the stack trace are returned in the protobuf response.- Specified by:
call
in interfaceRpcServerInterface
- Throws:
IOException
-
logResponse
void logResponse(org.apache.hbase.thirdparty.com.google.protobuf.Message param, String methodName, String call, boolean tooLarge, boolean tooSlow, String clientAddress, long startTime, int processingTime, int qTime, long responseSize, long blockBytesScanned, long fsReadTime, String userName) Logs an RPC response to the LOG file, producing valid JSON objects for client Operations.- Parameters:
param
- The parameters received in the call.methodName
- The name of the method invokedcall
- The string representation of the calltooLarge
- To indicate if the event is tooLargetooSlow
- To indicate if the event is tooSlowclientAddress
- 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.blockBytesScanned
- The size of block bytes scanned to retrieve the response.userName
- UserName of the current RPC Call
-
isTooSlow
-
isTooLarge
-
truncateTraceLog
Truncate to number of chars decided by conf hbase.ipc.trace.log.max.length if TRACE is on else to 150 chars Refer to Jira HBASE-20826 and HBASE-20942- Parameters:
strParam
- stringifiedParam to be truncated- Returns:
- truncated trace log string
-
setErrorHandler
Set the handler for calling out of RPC for error conditions.- Specified by:
setErrorHandler
in interfaceRpcServerInterface
- Parameters:
handler
- the handler implementation
-
getErrorHandler
- Specified by:
getErrorHandler
in interfaceRpcServerInterface
-
getMetrics
Returns the metrics instance for reporting RPC call statistics- Specified by:
getMetrics
in interfaceRpcServerInterface
-
addCallSize
Description copied from interface:RpcServerInterface
Add/subtract from the current size of all outstanding calls. Called on setup of a call to add call total size and then again at end of a call to remove the call size.- Specified by:
addCallSize
in interfaceRpcServerInterface
- Parameters:
diff
- Change (plus or minus)
-
authorize
public void authorize(org.apache.hadoop.security.UserGroupInformation user, org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ConnectionHeader connection, InetAddress addr) throws org.apache.hadoop.security.authorize.AuthorizationException Authorize the incoming client connection.- Parameters:
user
- client userconnection
- incoming connectionaddr
- InetAddress of incoming connection- Throws:
org.apache.hadoop.security.authorize.AuthorizationException
- when the client isn't authorized to talk the protocol
-
channelRead
This is a wrapper aroundReadableByteChannel.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.- Parameters:
channel
- writable byte channel to write onbuffer
- buffer to write- Returns:
- number of bytes written
- Throws:
IOException
- e- See Also:
-
channelIO
private static int channelIO(ReadableByteChannel readCh, WritableByteChannel writeCh, ByteBuffer buf) throws IOException Helper forchannelRead(java.nio.channels.ReadableByteChannel, java.nio.ByteBuffer)
. Only one of readCh or writeCh should be non-null.- Parameters:
readCh
- read channelwriteCh
- write channelbuf
- buffer to read or write into/out of- Returns:
- bytes written
- Throws:
IOException
- e- See Also:
-
getCurrentCall
Needed for features such as delayed calls. We need to be able to store the current call so that we can complete it later or ask questions of what is supported by the current ongoing call.- Returns:
- An RpcCallContext backed by the currently ongoing call (gotten from a thread local)
-
isInRpcCallContext
-
unsetCurrentCall
Used byRegionProcedureStore
. For master's rpc call, it may generate new procedure and mutate the region which store procedure. There are some check about rpc when mutate region, such as rpc timeout check. So unset the rpc call to avoid the rpc check.- Returns:
- the currently ongoing rpc call
-
setCurrentCall
Used byRegionProcedureStore
. Set the rpc call back after mutate region. -
getRequestUser
Returns the user credentials associated with the current RPC request or not present if no credentials were provided.- Returns:
- A User
-
getNumOpenConnections
The number of open RPC conections- Returns:
- the number of open rpc connections
-
getRequestUserName
Returns the username for any user associated with the current RPC request or not present if no user is set. -
getRemoteAddress
Returns the address of the remote client associated with the current RPC request or not present if no address is set. -
getServiceAndInterface
protected static RpcServer.BlockingServiceAndInterface getServiceAndInterface(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) - Parameters:
serviceName
- Some arbitrary string that represents a 'service'.services
- Available service instances- Returns:
- Matching BlockingServiceAndInterface pair
-
getServiceInterface
protected static Class<?> getServiceInterface(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) - Parameters:
serviceName
- Some arbitrary string that represents a 'service'.services
- Available services and their service interfaces.- Returns:
- Service interface class for
serviceName
-
getService
protected static org.apache.hbase.thirdparty.com.google.protobuf.BlockingService getService(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) - Parameters:
serviceName
- Some arbitrary string that represents a 'service'.services
- Available services and their service interfaces.- Returns:
- BlockingService that goes with the passed
serviceName
-
getStatus
-
getRemoteIp
Returns the remote side ip address when invoked inside an RPC Returns null incase of an error. -
getScheduler
- Specified by:
getScheduler
in interfaceRpcServerInterface
-
getByteBuffAllocator
Description copied from interface:RpcServerInterface
Allocator to allocate/free the ByteBuffers, those ByteBuffers can be on-heap or off-heap.- Specified by:
getByteBuffAllocator
in interfaceRpcServerInterface
- Returns:
- byte buffer allocator
-
setRsRpcServices
- Specified by:
setRsRpcServices
in interfaceRpcServerInterface
-
setNamedQueueRecorder
Description copied from interface:RpcServerInterface
Set Online SlowLog Provider- Specified by:
setNamedQueueRecorder
in interfaceRpcServerInterface
- Parameters:
namedQueueRecorder
- instance ofNamedQueueRecorder
-
needAuthorization
-
getServices
-