diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java index 975fac6..b017e1d 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java @@ -358,16 +358,11 @@ public class HBaseClient { /** * Add a call to this connection's call queue and notify * a listener; synchronized. - * Returns false if called during shutdown. * @param call to add - * @return true if the call was added. */ - protected synchronized boolean addCall(Call call) { - if (shouldCloseConnection.get()) - return false; + protected synchronized void addCall(Call call) { calls.put(call.id, call); notify(); - return true; } /** This class sends a ping to the remote side when timeout on @@ -1284,20 +1279,22 @@ public class HBaseClient { * refs for keys in HashMap properly. For now its ok. */ ConnectionId remoteId = new ConnectionId(addr, protocol, ticket, rpcTimeout); - do { - synchronized (connections) { - connection = connections.get(remoteId); - if (connection == null) { - connection = new Connection(remoteId); - connections.put(remoteId, connection); - } + synchronized (connections) { + connection = connections.get(remoteId); + if (connection == null) { + connection = new Connection(remoteId); + connections.put(remoteId, connection); } - } while (!connection.addCall(call)); + } + connection.addCall(call); //we don't invoke the method below inside "synchronized (connections)" //block above. The reason for that is if the server happens to be slow, //it will take longer to establish a connection and that will slow the //entire system down. + //Moreover, if the connection is currently created, there will be many threads + // waiting here; as setupIOstreams is synchronized. If the connection fails with a + // timeout, they will all fail simultaneously. This is checked in setupIOstreams. connection.setupIOstreams(); return connection; }