Package org.apache.hadoop.ipc
Class Server
java.lang.Object
org.apache.hadoop.ipc.Server
An abstract IPC service. IPC calls take a single
Writable as a
parameter, and return a Writable as their value. A service runs on
a port and is defined by a parameter class and a value class.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumorg.apache.hadoop.ipc.Server.AuthProtocolstatic classorg.apache.hadoop.ipc.Server.CallA generic call queued for handling.classorg.apache.hadoop.ipc.Server.ConnectionReads calls from a connection and queues them for handling. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.Loggerstatic final org.slf4j.Loggerprotected final org.apache.hadoop.ipc.metrics.RpcDetailedMetricsprotected final org.apache.hadoop.ipc.metrics.RpcMetrics -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedServer(String bindAddress, int port, Class<? extends Writable> rpcRequestClass, int handlerCount, int numReaders, int queueSizePerHandler, Configuration conf, String serverName, SecretManager<? extends TokenIdentifier> secretManager) protectedServer(String bindAddress, int port, Class<? extends Writable> rpcRequestClass, int handlerCount, int numReaders, int queueSizePerHandler, Configuration conf, String serverName, SecretManager<? extends TokenIdentifier> secretManager, String portRangeConfig) Constructs a server listening on the named port and address.protectedServer(String bindAddress, int port, Class<? extends Writable> paramClass, int handlerCount, Configuration conf) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuxiliaryListener(int auxiliaryPort) voidaddSuppressedLoggingExceptions(Class<?>... exceptionClass) Add exception classes which server won't log at all.voidaddTerseExceptions(Class<?>... exceptionClass) Add exception classes for which server won't log stack traces.static voidbind(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.static voidbind(ServerSocket socket, InetSocketAddress address, int backlog, Configuration conf, String rangeConf) Deprecated.abstract Writablecall(RPC.RpcKind rpcKind, String protocol, Writable param, long receiveTime) Called for each call.static Serverget()Return the set of all the configured auxiliary socket addresses NameNode RPC is listening on.static StringReturns the SASL qop for the current call, if the current call is set, and the SASL negotiation is done.static intReturns the currently active RPC call's sequential ID number.intThe number of rpc calls in the queue.static intstatic byte[]static ThreadLocal<org.apache.hadoop.ipc.Server.Call>Return the socket (ip+port) on which the RPC server is listening to.longprotected intintThe maximum size of the rpc call queue of this server.longThe number of RPC connections dropped due to too many connections.intintThe number of open RPC conectionsintThe number of reader threads for this server.intgetPort()Get the port on which the IPC Server is listening for incoming connections.static intstatic Stringlongstatic Stringstatic InetAddressstatic intstatic UserGroupInformationReturns the RPC remote user when invoked inside an RPC.org.apache.hadoop.ipc.metrics.RpcDetailedMetricsstatic org.apache.hadoop.ipc.RPC.RpcInvokergetRpcInvoker(RPC.RpcKind rpcKind) org.apache.hadoop.ipc.metrics.RpcMetricsReturns a handle to the rpcMetrics (required in tests)protected org.apache.hadoop.ipc.RPC.RpcInvokergetServerRpcInvoker(RPC.RpcKind rpcKind) org.apache.hadoop.security.authorize.ServiceAuthorizationManagergetServiceAuthorizationManager()Returns a handle to the serviceAuthorizationManager (required in tests)longlongbooleanbooleanChecks if LogSlowRPC is set true.static booleanbooleanbooleanvoidjoin()Wait for the server to be stopped.voidqueueCall(org.apache.hadoop.ipc.Server.Call call) voidvoidrefreshServiceAcl(Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider provider) Refresh the service authorization ACL for the service handled by this server.voidrefreshServiceAclWithLoadedConfiguration(Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider provider) Refresh the service authorization ACL for the service handled by this server using the specified Configuration.static voidregisterProtocolEngine(RPC.RpcKind rpcKind, Class<? extends Writable> rpcRequestWrapperClass, org.apache.hadoop.ipc.RPC.RpcInvoker rpcInvoker) Register a RPC kind and the class to deserialize the rpc request.voidsetAlignmentContext(org.apache.hadoop.ipc.AlignmentContext alignmentContext) Set alignment context to pass state info thru RPC.voidsetClientBackoffEnabled(boolean value) voidsetLogSlowRPC(boolean logSlowRPCFlag) Sets slow RPC flag.voidsetLogSlowRPCThresholdTime(long logSlowRPCThresholdMs) voidsetSocketSendBufSize(int size) Sets the socket buffer size used for responding to RPCs.voidsetTracer(org.apache.hadoop.tracing.Tracer t) voidstart()Starts the service.voidstop()Stops the service.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
AUDITLOG
public static final org.slf4j.Logger AUDITLOG -
rpcMetrics
protected final org.apache.hadoop.ipc.metrics.RpcMetrics rpcMetrics -
rpcDetailedMetrics
protected final org.apache.hadoop.ipc.metrics.RpcDetailedMetrics rpcDetailedMetrics
-
-
Constructor Details
-
Server
protected Server(String bindAddress, int port, Class<? extends Writable> paramClass, int handlerCount, Configuration conf) throws IOException - Throws:
IOException
-
Server
protected Server(String bindAddress, int port, Class<? extends Writable> rpcRequestClass, int handlerCount, int numReaders, int queueSizePerHandler, Configuration conf, String serverName, SecretManager<? extends TokenIdentifier> secretManager) throws IOException - Throws:
IOException
-
Server
protected Server(String bindAddress, int port, Class<? extends Writable> rpcRequestClass, int handlerCount, int numReaders, int queueSizePerHandler, Configuration conf, String serverName, SecretManager<? extends TokenIdentifier> secretManager, String portRangeConfig) throws IOException Constructs a server listening on the named port and address. Parameters passed must be of the named class. ThehandlerCountdetermines the number of handler threads that will be used to process calls. If queueSizePerHandler or numReaders are not -1 they will be used instead of parameters from configuration. Otherwise the configuration will be picked up. If rpcRequestClass is null then the rpcRequestClass must have been registered viaregisterProtocolEngine(RPC.RpcKind, Class, RPC.RpcInvoker)This parameter has been retained for compatibility with existing tests and usage.- Parameters:
bindAddress- input bindAddress.port- input port.rpcRequestClass- input rpcRequestClass.handlerCount- input handlerCount.numReaders- input numReaders.queueSizePerHandler- input queueSizePerHandler.conf- input Configuration.serverName- input serverName.secretManager- input secretManager.portRangeConfig- input portRangeConfig.- Throws:
IOException- raised on errors performing I/O.
-
-
Method Details
-
addTerseExceptions
Add exception classes for which server won't log stack traces.- Parameters:
exceptionClass- exception classes
-
addSuppressedLoggingExceptions
Add exception classes which server won't log at all.- Parameters:
exceptionClass- exception classes
-
setAlignmentContext
public void setAlignmentContext(org.apache.hadoop.ipc.AlignmentContext alignmentContext) Set alignment context to pass state info thru RPC.- Parameters:
alignmentContext- alignment state context
-
registerProtocolEngine
public static void registerProtocolEngine(RPC.RpcKind rpcKind, Class<? extends Writable> rpcRequestWrapperClass, org.apache.hadoop.ipc.RPC.RpcInvoker rpcInvoker) Register a RPC kind and the class to deserialize the rpc request. Called by static initializers of rpcKind Engines- Parameters:
rpcKind- - input rpcKind.rpcRequestWrapperClass- - this class is used to deserialze the the rpc request.rpcInvoker- - use to process the calls on SS.
-
getRpcRequestWrapper
-
getServerRpcInvoker
-
getRpcInvoker
-
get
- Returns:
- Returns the server instance called under or null. May be called under
call(Writable, long)implementations, and underWritablemethods of paramters and return values. Permits applications to access the server context.
-
getCurCall
- Returns:
- Get the current call.
-
getCallId
public static int getCallId()Returns the currently active RPC call's sequential ID number. A negative call ID indicates an invalid value, such as if there is no currently active RPC call.- Returns:
- int sequential ID number of currently active RPC call
-
getCallRetryCount
public static int getCallRetryCount()- Returns:
- The current active RPC call's retry count. -1 indicates the retry cache is not supported in the client side.
-
getRemoteIp
- Returns:
- Returns the remote side ip address when invoked inside an RPC Returns null in case of an error.
-
getRemotePort
public static int getRemotePort()- Returns:
- Returns the remote side port when invoked inside an RPC Returns 0 in case of an error.
-
getAuxiliaryPortEstablishedQOP
Returns the SASL qop for the current call, if the current call is set, and the SASL negotiation is done. Otherwise return null Note this only returns established QOP for auxiliary port, and returns null for primary (non-auxiliary) port. Also note that CurCall is thread local object. So in fact, different handler threads will process different CurCall object. Also, only return for RPC calls, not supported for other protocols.- Returns:
- the QOP of the current connection.
-
getClientId
public static byte[] getClientId()- Returns:
- Returns the clientId from the current RPC request.
-
getRemoteAddress
- Returns:
- Returns remote address as a string when invoked inside an RPC. Returns null in case of an error.
-
getRemoteUser
Returns the RPC remote user when invoked inside an RPC. Note this may be different than the current user if called within another doAs- Returns:
- connection's UGI or null if not an RPC
-
getProtocol
-
isRpcInvocation
public static boolean isRpcInvocation()- Returns:
- Return true if the invocation was through an RPC.
-
getPriorityLevel
public static int getPriorityLevel()- Returns:
- Return the priority level assigned by call queue to an RPC Returns 0 in case no priority is assigned.
-
isLogSlowRPC
public boolean isLogSlowRPC()Checks if LogSlowRPC is set true.- Returns:
- true, if LogSlowRPC is set true, false, otherwise.
-
getLogSlowRPCThresholdTime
public long getLogSlowRPCThresholdTime() -
getNumInProcessHandler
public int getNumInProcessHandler() -
getTotalRequests
public long getTotalRequests() -
getTotalRequestsPerSecond
public long getTotalRequestsPerSecond() -
setLogSlowRPC
@VisibleForTesting public void setLogSlowRPC(boolean logSlowRPCFlag) Sets slow RPC flag.- Parameters:
logSlowRPCFlag- input logSlowRPCFlag.
-
setLogSlowRPCThresholdTime
@VisibleForTesting public void setLogSlowRPCThresholdTime(long logSlowRPCThresholdMs) -
getPurgeIntervalNanos
@VisibleForTesting public long getPurgeIntervalNanos() -
bind
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException A convenience method to bind to a given address and report better exceptions if the address is not a valid host.- Parameters:
socket- the socket to bindaddress- the address to bind tobacklog- the number of connections allowed in the queue- Throws:
BindException- if the address can't be boundUnknownHostException- if the address isn't a valid host nameIOException- other random errors from bind
-
bind
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog, Configuration conf, String rangeConf) throws IOException - Throws:
IOException
-
getRpcMetrics
@VisibleForTesting public org.apache.hadoop.ipc.metrics.RpcMetrics getRpcMetrics()Returns a handle to the rpcMetrics (required in tests)- Returns:
- rpc metrics
-
getRpcDetailedMetrics
@VisibleForTesting public org.apache.hadoop.ipc.metrics.RpcDetailedMetrics getRpcDetailedMetrics() -
refreshServiceAcl
public void refreshServiceAcl(Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider provider) Refresh the service authorization ACL for the service handled by this server.- Parameters:
conf- input Configuration.provider- input PolicyProvider.
-
refreshServiceAclWithLoadedConfiguration
@Private public void refreshServiceAclWithLoadedConfiguration(Configuration conf, org.apache.hadoop.security.authorize.PolicyProvider provider) Refresh the service authorization ACL for the service handled by this server using the specified Configuration.- Parameters:
conf- input Configuration.provider- input provider.
-
getServiceAuthorizationManager
@LimitedPrivate({"HDFS","MapReduce"}) public org.apache.hadoop.security.authorize.ServiceAuthorizationManager getServiceAuthorizationManager()Returns a handle to the serviceAuthorizationManager (required in tests)- Returns:
- instance of ServiceAuthorizationManager for this server
-
refreshCallQueue
-
queueCall
public void queueCall(org.apache.hadoop.ipc.Server.Call call) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
addAuxiliaryListener
- Throws:
IOException
-
setSocketSendBufSize
public void setSocketSendBufSize(int size) Sets the socket buffer size used for responding to RPCs.- Parameters:
size- input size.
-
setTracer
public void setTracer(org.apache.hadoop.tracing.Tracer t) -
start
public void start()Starts the service. Must be called before any calls will be handled. -
stop
public void stop()Stops the service. No new calls will be handled after this is called. -
join
Wait for the server to be stopped. Does not wait for all subthreads to finish. Seestop().- Throws:
InterruptedException- if the thread is interrupted.
-
getListenerAddress
Return the socket (ip+port) on which the RPC server is listening to.- Returns:
- the socket (ip+port) on which the RPC server is listening to.
-
getAuxiliaryListenerAddresses
Return the set of all the configured auxiliary socket addresses NameNode RPC is listening on. If there are none, or it is not configured at all, an empty set is returned.- Returns:
- the set of all the auxiliary addresses on which the RPC server is listening on.
-
call
Deprecated.Usecall(RPC.RpcKind, String, Writable, long)insteadCalled for each call.- Parameters:
param- input param.receiveTime- input receiveTime.- Returns:
- Call
- Throws:
Exception- if any error occurs.
-
call
public abstract Writable call(RPC.RpcKind rpcKind, String protocol, Writable param, long receiveTime) throws Exception Called for each call.- Parameters:
rpcKind- input rpcKind.protocol- input protocol.param- input param.receiveTime- input receiveTime.- Returns:
- Call.
- Throws:
Exception- raised on errors performing I/O.
-
getPort
public int getPort()Get the port on which the IPC Server is listening for incoming connections. This could be an ephemeral port too, in which case we return the real port on which the Server has bound.- Returns:
- port on which IPC Server is listening
-
getNumOpenConnections
public int getNumOpenConnections()The number of open RPC conections- Returns:
- the number of open rpc connections
-
getNumOpenConnectionsPerUser
- Returns:
- Get the NumOpenConnections/User.
-
getNumDroppedConnections
public long getNumDroppedConnections()The number of RPC connections dropped due to too many connections.- Returns:
- the number of dropped rpc connections
-
getCallQueueLen
public int getCallQueueLen()The number of rpc calls in the queue.- Returns:
- The number of rpc calls in the queue.
-
isClientBackoffEnabled
public boolean isClientBackoffEnabled() -
setClientBackoffEnabled
public void setClientBackoffEnabled(boolean value) -
isServerFailOverEnabled
@VisibleForTesting public boolean isServerFailOverEnabled() -
isServerFailOverEnabledByQueue
@VisibleForTesting public boolean isServerFailOverEnabledByQueue() -
getMaxQueueSize
public int getMaxQueueSize()The maximum size of the rpc call queue of this server.- Returns:
- The maximum size of the rpc call queue.
-
getNumReaders
public int getNumReaders()The number of reader threads for this server.- Returns:
- The number of reader threads.
-
getMaxIdleTime
protected int getMaxIdleTime() -
getServerName
-
call(RPC.RpcKind, String, Writable, long)instead