Package org.apache.hadoop.ipc

Class Server

java.lang.Object
org.apache.hadoop.ipc.Server

@Public @Evolving public abstract class Server extends Object
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:
  • 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. The handlerCount determines 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 via registerProtocolEngine(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

      public void addTerseExceptions(Class<?>... exceptionClass)
      Add exception classes for which server won't log stack traces.
      Parameters:
      exceptionClass - exception classes
    • addSuppressedLoggingExceptions

      public void addSuppressedLoggingExceptions(Class<?>... exceptionClass)
      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

      public Class<? extends Writable> getRpcRequestWrapper(RpcHeaderProtos.RpcKindProto rpcKind)
    • getServerRpcInvoker

      protected org.apache.hadoop.ipc.RPC.RpcInvoker getServerRpcInvoker(RPC.RpcKind rpcKind)
    • getRpcInvoker

      public static org.apache.hadoop.ipc.RPC.RpcInvoker getRpcInvoker(RPC.RpcKind rpcKind)
    • get

      public static Server get()
      Returns:
      Returns the server instance called under or null. May be called under call(Writable, long) implementations, and under Writable methods of paramters and return values. Permits applications to access the server context.
    • getCurCall

      @VisibleForTesting public static ThreadLocal<org.apache.hadoop.ipc.Server.Call> 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

      public static InetAddress 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

      public static String 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

      public static String getRemoteAddress()
      Returns:
      Returns remote address as a string when invoked inside an RPC. Returns null in case of an error.
    • getRemoteUser

      public static UserGroupInformation 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

      public static String 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 bind
      address - the address to bind to
      backlog - the number of connections allowed in the queue
      Throws:
      BindException - if the address can't be bound
      UnknownHostException - if the address isn't a valid host name
      IOException - 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

      public void refreshCallQueue(Configuration conf)
    • queueCall

      public void queueCall(org.apache.hadoop.ipc.Server.Call call) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • addAuxiliaryListener

      public void addAuxiliaryListener(int auxiliaryPort) throws IOException
      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

      public void join() throws InterruptedException
      Wait for the server to be stopped. Does not wait for all subthreads to finish. See stop().
      Throws:
      InterruptedException - if the thread is interrupted.
    • getListenerAddress

      public InetSocketAddress 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

      public Set<InetSocketAddress> 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 public Writable call(Writable param, long receiveTime) throws Exception
      Called 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

      public String 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

      public String getServerName()