You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2018/09/06 06:56:42 UTC
[4/4] hbase git commit: HBASE-21061 Fix inconsistent synchronization
in RpcServer
HBASE-21061 Fix inconsistent synchronization in RpcServer
move variables that we don't need synchronized access to out of the critical block.
Signed-off-by: Mike Drob <md...@apache.org>
Conflicts:
hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/f5a06e07
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f5a06e07
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f5a06e07
Branch: refs/heads/branch-1.2
Commit: f5a06e07eb841c6600337f01ad6b9ff80e41df52
Parents: bd76de7
Author: Sean Busbey <bu...@apache.org>
Authored: Sat Aug 25 21:28:03 2018 -0500
Committer: Sean Busbey <bu...@apache.org>
Committed: Thu Sep 6 01:54:23 2018 -0500
----------------------------------------------------------------------
.../org/apache/hadoop/hbase/ipc/RpcServer.java | 55 +++++++++++---------
1 file changed, 31 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/f5a06e07/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
index 2503204..4f8101b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
@@ -1557,7 +1557,7 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver {
* @throws IOException
* @throws InterruptedException
*/
- public synchronized int readAndProcess() throws IOException, InterruptedException {
+ public int readAndProcess() throws IOException, InterruptedException {
// If we have not read the connection setup preamble, look to see if that is on the wire.
if (!connectionPreambleRead) {
int count = readPreamble();
@@ -1585,33 +1585,40 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver {
}
}
- // We have read a length and we have read the preamble. It is either the connection header
- // or it is a request.
- if (data == null) {
- dataLengthBuffer.flip();
- int dataLength = dataLengthBuffer.getInt();
- if (dataLength == RpcClient.PING_CALL_ID) {
- if (!useWrap) { //covers the !useSasl too
- dataLengthBuffer.clear();
- return 0; //ping message
+ final boolean useWrap = this.useWrap;
+
+ // we're guarding against data being modified concurrently
+ // while trying to keep other instance members out of the block
+ synchronized(this) {
+ // We have read a length and we have read the preamble. It is either the connection header
+ // or it is a request.
+ if (data == null) {
+ dataLengthBuffer.flip();
+ int dataLength = dataLengthBuffer.getInt();
+ if (dataLength == RpcClient.PING_CALL_ID) {
+ if (!useWrap) { //covers the !useSasl too
+ dataLengthBuffer.clear();
+ return 0; //ping message
+ }
}
- }
- if (dataLength < 0) { // A data length of zero is legal.
- throw new IllegalArgumentException("Unexpected data length "
- + dataLength + "!! from " + getHostAddress());
- }
- data = ByteBuffer.allocate(dataLength);
- // Increment the rpc count. This counter will be decreased when we write
- // the response. If we want the connection to be detected as idle properly, we
- // need to keep the inc / dec correct.
- incRpcCount();
- }
+ if (dataLength < 0) { // A data length of zero is legal.
+ throw new IllegalArgumentException("Unexpected data length "
+ + dataLength + "!! from " + getHostAddress());
+ }
+ data = ByteBuffer.allocate(dataLength);
+
+ // Increment the rpc count. This counter will be decreased when we write
+ // the response. If we want the connection to be detected as idle properly, we
+ // need to keep the inc / dec correct.
+ incRpcCount();
+ }
- count = channelRead(channel, data);
+ count = channelRead(channel, data);
- if (count >= 0 && data.remaining() == 0) { // count==0 if dataLength == 0
- process();
+ if (count >= 0 && data.remaining() == 0) { // count==0 if dataLength == 0
+ process();
+ }
}
return count;