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 33786b7..383cf28 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 @@ -105,7 +105,7 @@ public class HBaseClient { public static final Log LOG = LogFactory .getLog("org.apache.hadoop.ipc.HBaseClient"); - protected final PoolMap connections; + protected volatile PoolMap connections; protected int counter; // counter for call ids protected final AtomicBoolean running = new AtomicBoolean(true); // if client runs @@ -1409,11 +1409,15 @@ public class HBaseClient { * refs for keys in HashMap properly. For now its ok. */ ConnectionId remoteId = new ConnectionId(addr, protocol, ticket, rpcTimeout); - synchronized (connections) { - connection = connections.get(remoteId); - if (connection == null) { - connection = createConnection(remoteId); - connections.put(remoteId, connection); + connection = connections.get(remoteId); + if (connection == null) { + synchronized (connections) { + // Recheck since another thread might have added a connection. + connection = connections.get(remoteId); + if (connection == null) { + connection = createConnection(remoteId); + connections.put(remoteId, connection); + } } } connection.addCall(call);