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
Modifier and TypeClassDescriptionprivate class
If the client wants to interrupt its calls easily (i.e. -
Field Summary
Modifier and TypeFieldDescriptionprivate final AtomicInteger
private final ConcurrentMap<Integer,
Call> private final BlockingRpcConnection.CallSender
private boolean
private byte[]
private byte[]
private DataInputStream
private static final org.slf4j.Logger
private DataOutputStream
private final Object
private final BlockingRpcClient
private HBaseSaslRpcClient
protected Socket
private Thread
private final String
private boolean
Fields 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
callTimeout
(Call call) private String
chooseServerPrincipal
(InputStream inStream, OutputStream outStream) void
Does the clean up work after the connection is removed from the connection poolprivate void
private void
private void
createStreams
(InputStream inStream, OutputStream outStream) private void
private void
getConnectionRegistry
(InputStream inStream, OutputStream outStream, Call connectionRegistryCall) private void
handleConnectionFailure
(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 void
handleSaslConnectionFailure
(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.boolean
isActive()
Tell the idle connection sweeper whether we could be swept.private boolean
For use in the reader thread, tests if the current reader thread is the one expected to be running.private void
negotiateCryptoAes
(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CryptoCipherMeta cryptoCipherMeta) private void
private void
void
run()
void
sendRequest
(Call call, HBaseRpcController pcrc) protected void
private void
setupIOstreams
(Call connectionRegistryCall) private boolean
setupSaslConnection
(InputStream in2, OutputStream out2, String serverPrincipal) void
shutdown()
Just close connection.private boolean
private void
Write the connection header.private void
Write the RPC header:<MAGIC WORD -- 'HBas'> <ONEBYTE_VERSION> <ONEBYTE_AUTH_TYPE>
private void
writeRequest
(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
-
readerThreadLock
-
attempts
-
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:
IOException
InterruptedException
-
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
-
isCurrentThreadExpected
For use in the reader thread, tests if the current reader thread is the one expected to be running. When closeConn is called, the reader thread is expected to end. setupIOStreams then creates a new thread and updates the thread pointer. At that point, the new thread should be the only one running. We use this method to guard against cases where the old thread may be erroneously running or closing the connection in error states. -
callTimeout
- Specified by:
callTimeout
in classRpcConnection
-
closeSocket
-
closeConn
-
shutdown
Description copied from class:RpcConnection
Just close connection. Do not need to remove from connection pool.- Specified by:
shutdown
in classRpcConnection
-
cleanupConnection
Description copied from class:RpcConnection
Does the clean up work after the connection is removed from the connection pool- Specified by:
cleanupConnection
in classRpcConnection
-
sendRequest
- Specified by:
sendRequest
in classRpcConnection
- Throws:
IOException
-
isActive
Description copied from class:RpcConnection
Tell the idle connection sweeper whether we could be swept.- Specified by:
isActive
in classRpcConnection
-