You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/03/16 20:07:13 UTC

svn commit: r1082262 - in /hbase/branches/0.90: CHANGES.txt src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java

Author: nspiegelberg
Date: Wed Mar 16 19:07:13 2011
New Revision: 1082262

URL: http://svn.apache.org/viewvc?rev=1082262&view=rev
Log:
 HBASE-3653  Parallelize Server Requests on HBase Client

Modified:
    hbase/branches/0.90/CHANGES.txt
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java

Modified: hbase/branches/0.90/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/CHANGES.txt?rev=1082262&r1=1082261&r2=1082262&view=diff
==============================================================================
--- hbase/branches/0.90/CHANGES.txt (original)
+++ hbase/branches/0.90/CHANGES.txt Wed Mar 16 19:07:13 2011
@@ -54,6 +54,7 @@ Release 0.90.2 - February 9th, 2011
    HBASE-3600  Update our jruby to 1.6.0
    HBASE-3440  Clean out load_table.rb and make sure all roads lead to
                completebulkload tool (Vidhyashankar Venkataraman via Stack)
+   HBASE-3653  Parallelize Server Requests on HBase Client
 
 
 Release 0.90.1 - February 9th, 2011

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1082262&r1=1082261&r2=1082262&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java Wed Mar 16 19:07:13 2011
@@ -247,6 +247,7 @@ public class HConnectionManager {
 
     private final Map<String, HRegionInterface> servers =
       new ConcurrentHashMap<String, HRegionInterface>();
+    private final ConcurrentHashMap<String, String> connectionLock = new ConcurrentHashMap<String, String>();
 
     /**
      * Map of table to table {@link HRegionLocation}s.  The table key is made
@@ -948,21 +949,30 @@ public class HConnectionManager {
         getMaster();
       }
       HRegionInterface server;
-      synchronized (this.servers) {
-        // See if we already have a connection
-        server = this.servers.get(regionServer.toString());
-        if (server == null) { // Get a connection
-          try {
-            server = (HRegionInterface)HBaseRPC.waitForProxy(
-                serverInterfaceClass, HBaseRPCProtocolVersion.versionID,
-                regionServer.getInetSocketAddress(), this.conf,
-                this.maxRPCAttempts, this.rpcTimeout, this.rpcTimeout);
-          } catch (RemoteException e) {
-            LOG.warn("RemoteException connecting to RS", e);
-            // Throw what the RemoteException was carrying.
-            throw RemoteExceptionHandler.decodeRemoteException(e);
+      String rsName = regionServer.toString();
+      // See if we already have a connection (common case)
+      server = this.servers.get(rsName);
+      if (server == null) {
+        // create a unique lock for this RS (if necessary)
+        this.connectionLock.putIfAbsent(rsName, rsName);
+        // get the RS lock
+        synchronized (this.connectionLock.get(rsName)) {
+          // do one more lookup in case we were stalled above
+          server = this.servers.get(rsName);
+          if (server == null) {
+            try {
+              // definitely a cache miss. establish an RPC for this RS
+              server = (HRegionInterface) HBaseRPC.waitForProxy(
+                  serverInterfaceClass, HBaseRPCProtocolVersion.versionID,
+                  regionServer.getInetSocketAddress(), this.conf,
+                  this.maxRPCAttempts, this.rpcTimeout, this.rpcTimeout);
+              this.servers.put(rsName, server);
+            } catch (RemoteException e) {
+              LOG.warn("RemoteException connecting to RS", e);
+              // Throw what the RemoteException was carrying.
+              throw RemoteExceptionHandler.decodeRemoteException(e);
+            }
           }
-          this.servers.put(regionServer.toString(), server);
         }
       }
       return server;