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
Nested ClassesModifier and TypeClassDescriptionstatic classDatastructure for passing aBlockingServiceand its associated class of protobuf service interface.protected static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected static final org.slf4j.Loggerprotected static final Stringprotected static final Stringprotected org.apache.hadoop.security.authorize.ServiceAuthorizationManagerprivate final booleanprotected AuthenticationTokenSecretManagerprotected final ByteBuffAllocatorprotected final InetSocketAddressprotected static final CallQueueTooBigExceptionprotected final LongAdderThis is a running count of the size in bytes of all outstanding calls whether currently executing or queued waiting to be run.protected final CellBlockBuilderprotected final org.apache.hadoop.conf.Configuration(package private) RpcCoprocessorHostprotected static final ThreadLocal<RpcCall>This is set to Call object before Handler invokes an RPC and ybdie after the call returns.static final byteprotected static final intHow many calls/handler are allowed in the queue.protected static final intstatic final intDefault value for above paramsprotected static final intprotected static final intprotected static final intprotected static final intprotected HBaseRPCErrorHandlerstatic final StringWhether we allow a fallback to SIMPLE auth for insecure clients when security is enabled.protected static final org.apache.hbase.thirdparty.com.google.gson.Gsonprivate booleanprotected booleanprotected static final Stringstatic final org.slf4j.Loggerstatic final Stringprotected final longMaximum size in bytes of the currently queued and running Calls.protected final intprotected MetricsHBaseServerprotected static final StringMinimum allowable timeout (in milliseconds) in rpc request's header.protected final intprotected static final ThreadLocal<MonitoredRPCHandler>Keeps MonitoredRPCHandler per handler thread.private static final Stringprivate static final Stringprivate static final Stringprivate NamedQueueRecorderUse to add online slowlog responsesprotected static final intWhen the read or write buffer size is larger than this limit, i/o will be done in chunks of this size.private RSRpcServicesUsed 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) booleanThis flag is used to indicate to sub threads when they should go down.protected final RpcSchedulerprotected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier>protected final Serverprotected final Stringprotected final List<RpcServer.BlockingServiceAndInterface>(package private) booleanThis 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 booleanprotected final booleanprotected static final Stringprotected final UserProviderprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected intprotected intprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionRpcServer(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 TypeMethodDescriptionvoidaddCallSize(long diff) Add/subtract from the current size of all outstanding calls.voidauthorize(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,ExtendedCellScanner> call(RpcCall call, MonitoredRPCHandler status) This is a server side method, which is invoked over RPC.private static intchannelIO(ReadableByteChannel readCh, WritableByteChannel writeCh, ByteBuffer buf) protected intchannelRead(ReadableByteChannel channel, ByteBuffer buffer) This is a wrapper aroundReadableByteChannel.read(java.nio.ByteBuffer).protected AuthenticationTokenSecretManagerAllocator to allocate/free the ByteBuffers, those ByteBuffers can be on-heap or off-heap.(package private) org.apache.hadoop.conf.ConfigurationgetConf()Needed for features such as delayed calls.static Optional<ServerCall<?>>Just return the current rpc call if it is aServerCalland also hasCellScannerattached.private static booleangetIsOnlineLogProviderEnabled(org.apache.hadoop.conf.Configuration conf) Returns the metrics instance for reporting RPC call statisticsabstract intThe 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 InetAddressReturns 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.Return RPC's instance ofRpcCoprocessorHostorg.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier>protected static org.apache.hbase.thirdparty.com.google.protobuf.BlockingServicegetService(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) protected static RpcServer.BlockingServiceAndInterfacegetServiceAndInterface(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) protected static Class<?>getServiceInterface(List<RpcServer.BlockingServiceAndInterface> services, String serviceName) protected static MonitoredRPCHandlerprivate static intgetWarnResponseSize(org.apache.hadoop.conf.Configuration conf) private static intgetWarnResponseTime(org.apache.hadoop.conf.Configuration conf) private static intgetWarnScanResponseSize(org.apache.hadoop.conf.Configuration conf) private static intgetWarnScanResponseTime(org.apache.hadoop.conf.Configuration conf) private voidinitializeCoprocessorHost(org.apache.hadoop.conf.Configuration conf) protected voidinitReconfigurable(org.apache.hadoop.conf.Configuration confToLoad) static booleanbooleanprivate booleanisTooLarge(RpcCall call, long responseSize, long responseBlockSize) private boolean(package private) voidlogResponse(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 booleanvoidonConfigurationChange(org.apache.hadoop.conf.Configuration newConf) This method would be called by theConfigurationManagerobject when theConfigurationobject is reloaded from disk.voidrefreshAuthManager(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider pp) Refresh authentication manager policy.private voidrefreshSlowLogConfiguration(org.apache.hadoop.conf.Configuration newConf) static voidsetCurrentCall(RpcCall rpcCall) Used byMasterRegion.voidsetErrorHandler(HBaseRPCErrorHandler handler) Set the handler for calling out of RPC for error conditions.voidsetNamedQueueRecorder(NamedQueueRecorder namedQueueRecorder) Set Online SlowLog ProvidervoidsetRsRpcServices(RSRpcServices rsRpcServices) voidsetSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager) (package private) StringtruncateTraceLog(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 byMasterRegion, to avoid hit row lock timeout when updating master region in a rpc call.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.hbase.ipc.RpcServerInterface
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
-
cpHost
-
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:ConfigurationObserverThis method would be called by theConfigurationManagerobject when theConfigurationobject is reloaded from disk.- Specified by:
onConfigurationChangein interfaceConfigurationObserver
-
refreshSlowLogConfiguration
-
getIsOnlineLogProviderEnabled
-
getWarnResponseTime
-
getWarnResponseSize
-
getWarnScanResponseTime
-
getWarnScanResponseSize
-
initReconfigurable
-
getConf
org.apache.hadoop.conf.Configuration getConf() -
isStarted
- Specified by:
isStartedin interfaceRpcServerInterface
-
refreshAuthManager
public void refreshAuthManager(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider pp) Description copied from interface:RpcServerInterfaceRefresh authentication manager policy.- Specified by:
refreshAuthManagerin 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,ExtendedCellScanner> 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:
callin 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:
setErrorHandlerin interfaceRpcServerInterface- Parameters:
handler- the handler implementation
-
getErrorHandler
- Specified by:
getErrorHandlerin interfaceRpcServerInterface
-
getMetrics
Returns the metrics instance for reporting RPC call statistics- Specified by:
getMetricsin interfaceRpcServerInterface
-
addCallSize
Description copied from interface:RpcServerInterfaceAdd/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:
addCallSizein 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)
-
getCurrentServerCallWithCellScanner
Just return the current rpc call if it is aServerCalland also hasCellScannerattached. Mainly used for reference counting asCellScannermay reference non heap memory. -
isInRpcCallContext
-
unsetCurrentCall
Used byMasterRegion, to avoid hit row lock timeout when updating master region in a rpc call. See HBASE-23895, HBASE-29251 and HBASE-29294 for more details.- Returns:
- the currently ongoing rpc call
-
setCurrentCall
Used byMasterRegion. 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:
getSchedulerin interfaceRpcServerInterface
-
getByteBuffAllocator
Description copied from interface:RpcServerInterfaceAllocator to allocate/free the ByteBuffers, those ByteBuffers can be on-heap or off-heap.- Specified by:
getByteBuffAllocatorin interfaceRpcServerInterface- Returns:
- byte buffer allocator
-
setRsRpcServices
- Specified by:
setRsRpcServicesin interfaceRpcServerInterface
-
setNamedQueueRecorder
Description copied from interface:RpcServerInterfaceSet Online SlowLog Provider- Specified by:
setNamedQueueRecorderin interfaceRpcServerInterface- Parameters:
namedQueueRecorder- instance ofNamedQueueRecorder
-
needAuthorization
-
getServices
-
initializeCoprocessorHost
-
getRpcCoprocessorHost
Description copied from interface:RpcServerInterfaceReturn RPC's instance ofRpcCoprocessorHost- Specified by:
getRpcCoprocessorHostin interfaceRpcServerInterface
-