Package org.apache.hadoop.hbase.ipc
Class BlockingRpcConnection
java.lang.Object
org.apache.hadoop.hbase.ipc.RpcConnection
org.apache.hadoop.hbase.ipc.BlockingRpcConnection
- All Implemented Interfaces:
Runnable
Thread that reads responses and notifies callers. Each connection owns a socket connected to a
remote address. Calls are multiplexed through this socket: responses may be delivered out of
order.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classIf the client wants to interrupt its calls easily (i.e. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap<Integer,Call> private final BlockingRpcConnection.CallSenderprivate booleanprivate byte[]private byte[]private DataInputStreamprivate static final org.slf4j.Loggerprivate DataOutputStreamprivate final BlockingRpcClientprivate HBaseSaslRpcClientprotected Socketprivate Threadprivate final Stringprivate booleanFields inherited from class org.apache.hadoop.hbase.ipc.RpcConnection
cellBlockBuilder, codec, compressor, conf, CRYPTO_AES_ENABLED_DEFAULT, CRYPTO_AES_ENABLED_KEY, lastTouched, metrics, provider, reloginMaxBackoff, remoteId, securityInfo, timeoutTimer, token, useSasl -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcallTimeout(Call call) private StringchooseServerPrincipal(InputStream inStream, OutputStream outStream) voidDoes the clean up work after the connection is removed from the connection poolprivate voidprivate voidprivate voidcreateStreams(InputStream inStream, OutputStream outStream) private voidprivate voidgetConnectionRegistry(InputStream inStream, OutputStream outStream, Call connectionRegistryCall) private voidhandleConnectionFailure(int curRetries, int maxRetries, IOException ioe) Handle connection failures If the current number of retries is equal to the max number of retries, stop retrying and throw the exception; Otherwise backoff N seconds and try connecting again.private voidhandleSaslConnectionFailure(int currRetries, int maxRetries, Exception ex, org.apache.hadoop.security.UserGroupInformation user, String serverPrincipal) If multiple clients with the same principal try to connect to the same server at the same time, the server assumes a replay attack is in progress.booleanisActive()Tell the idle connection sweeper whether we could be swept.private voidnegotiateCryptoAes(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CryptoCipherMeta cryptoCipherMeta) private voidprivate voidvoidrun()voidsendRequest(Call call, HBaseRpcController pcrc) protected voidprivate voidsetupIOstreams(Call connectionRegistryCall) private booleansetupSaslConnection(InputStream in2, OutputStream out2, String serverPrincipal) voidshutdown()Just close connection.private booleanprivate voidWrite the connection header.private voidWrite the RPC header:<MAGIC WORD -- 'HBas'> <ONEBYTE_VERSION> <ONEBYTE_AUTH_TYPE>private voidwriteRequest(Call call) Initiates a call by sending the parameter to the remote server.Methods inherited from class org.apache.hadoop.hbase.ipc.RpcConnection
chooseServerPrincipal, createSecurityPreambleCall, getConnectionHeader, getConnectionHeaderPreamble, getLastTouched, getRemoteInetAddress, getServerPrincipals, isKerberosAuth, randomSelect, readResponse, remoteId, saslNegotiationDone, scheduleTimeoutTask, setLastTouched
-
Field Details
-
LOG
-
rpcClient
-
threadName
-
thread
-
socket
-
in
-
out
-
saslRpcClient
-
calls
-
callSender
-
closed
-
connectionHeaderPreamble
-
connectionHeaderWithLength
-
waitingConnectionHeaderResponse
-
-
Constructor Details
-
BlockingRpcConnection
BlockingRpcConnection(BlockingRpcClient rpcClient, ConnectionId remoteId) throws IOException - Throws:
IOException
-
-
Method Details
-
setupConnection
- Throws:
IOException
-
handleConnectionFailure
private void handleConnectionFailure(int curRetries, int maxRetries, IOException ioe) throws IOException Handle connection failures If the current number of retries is equal to the max number of retries, stop retrying and throw the exception; Otherwise backoff N seconds and try connecting again. This Method is only called from inside setupIOstreams(), which is synchronized. Hence the sleep is synchronized; the locks will be retained.- Parameters:
curRetries- current number of retriesmaxRetries- max number of retries allowedioe- failure reason- Throws:
IOException- if max number of retries is reached
-
waitForWork
-
run
-
disposeSasl
-
setupSaslConnection
private boolean setupSaslConnection(InputStream in2, OutputStream out2, String serverPrincipal) throws IOException - Throws:
IOException
-
handleSaslConnectionFailure
private void handleSaslConnectionFailure(int currRetries, int maxRetries, Exception ex, org.apache.hadoop.security.UserGroupInformation user, String serverPrincipal) throws IOException, InterruptedException If multiple clients with the same principal try to connect to the same server at the same time, the server assumes a replay attack is in progress. This is a feature of kerberos. In order to work around this, what is done is that the client backs off randomly and tries to initiate the connection again. The other problem is to do with ticket expiry. To handle that, a relogin is attempted.The retry logic is governed by the
SaslClientAuthenticationProvider.canRetry()method. Some providers have the ability to obtain new credentials and then re-attempt to authenticate with HBase services. Other providers will continue to fail if they failed the first time -- for those, we want to fail-fast.- Throws:
IOExceptionInterruptedException
-
getConnectionRegistry
private void getConnectionRegistry(InputStream inStream, OutputStream outStream, Call connectionRegistryCall) throws IOException - Throws:
IOException
-
createStreams
-
chooseServerPrincipal
private String chooseServerPrincipal(InputStream inStream, OutputStream outStream) throws IOException - Throws:
IOException
-
setupIOstreams
- Throws:
IOException
-
writeConnectionHeaderPreamble
Write the RPC header:<MAGIC WORD -- 'HBas'> <ONEBYTE_VERSION> <ONEBYTE_AUTH_TYPE>- Throws:
IOException
-
writeConnectionHeader
Write the connection header.- Throws:
IOException
-
processResponseForConnectionHeader
- Throws:
IOException
-
negotiateCryptoAes
private void negotiateCryptoAes(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CryptoCipherMeta cryptoCipherMeta) throws IOException - Throws:
IOException
-
writeRequest
Initiates a call by sending the parameter to the remote server. Note: this is not called from the Connection thread, but by other threads.- Throws:
IOException- See Also:
-
readResponse
-
callTimeout
- Specified by:
callTimeoutin classRpcConnection
-
closeSocket
-
closeConn
-
shutdown
Description copied from class:RpcConnectionJust close connection. Do not need to remove from connection pool.- Specified by:
shutdownin classRpcConnection
-
cleanupConnection
Description copied from class:RpcConnectionDoes the clean up work after the connection is removed from the connection pool- Specified by:
cleanupConnectionin classRpcConnection
-
sendRequest
- Specified by:
sendRequestin classRpcConnection- Throws:
IOException
-
isActive
Description copied from class:RpcConnectionTell the idle connection sweeper whether we could be swept.- Specified by:
isActivein classRpcConnection
-