hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbau...@apache.org
Subject svn commit: r1360490 - in /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase: client/HConnectionManager.java regionserver/HRegionServer.java
Date Thu, 12 Jul 2012 00:26:39 GMT
Author: mbautin
Date: Thu Jul 12 00:26:39 2012
New Revision: 1360490

URL: http://svn.apache.org/viewvc?rev=1360490&view=rev
Log:
[jira] [HBASE-6324] [89-fb] Direct API calls from embedded Thrift server to regionserver

Author: mbautin

Summary: When handling Thrift calls in the regionserver we should not go through RPC to talk
to the local regionserver.

Test Plan:
Unit tests
Test cluster

Reviewers: aaiyer

Reviewed By: aaiyer

CC: Karthik, stack

Differential Revision: https://reviews.facebook.net/D3981

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1360490&r1=1360489&r2=1360490&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Thu Jul 12 00:26:39 2012
@@ -66,6 +66,7 @@ import org.apache.hadoop.hbase.ipc.HBase
 import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.MetaUtils;
 import org.apache.hadoop.hbase.util.SoftValueSortedMap;
@@ -1142,8 +1143,11 @@ public class HConnectionManager {
       if (getMaster) {
         getMaster();
       }
-      HRegionInterface server;
-      
+      HRegionInterface server = HRegionServer.getMainRS(regionServer);  
+      if (server != null) {
+        return server;
+      }
+
       try {
         // establish an RPC for this RS
         // set hbase.ipc.client.connect.max.retries to retry connection

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1360490&r1=1360489&r2=1360490&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Thu Jul 12 00:26:39 2012
@@ -144,6 +144,8 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.hadoop.hbase.util.HasThread;
 
+import com.google.common.base.Preconditions;
+
 /**
  * HRegionServer makes a set of HRegions available to clients.  It checks in with
  * the HMaster. There are many HRegionServers in a single HBase deployment.
@@ -225,6 +227,7 @@ public class HRegionServer implements HR
   // Server to handle client requests.  Default access so can be accessed by
   // unit tests.
   HBaseServer server;
+  private volatile boolean isRpcServerRunning;
 
   // Leases
   private Leases leases;
@@ -325,6 +328,9 @@ public class HRegionServer implements HR
   // profiling threadlocal
   public static final ThreadLocal<ProfilingData> threadLocalProfilingData = new ThreadLocal<ProfilingData>
();
 
+  /** Regionserver launched by the main method. Not used in tests. */
+  private static HRegionServer mainRegionServer;
+
   /**
    * Starts a HRegionServer at the default location
    * @param conf
@@ -721,6 +727,7 @@ public class HRegionServer implements HR
       thriftServer.shutdown();
     }
     this.leases.closeAfterLeasesExpire();
+    isRpcServerRunning = false;
     this.worker.stop();
     this.server.stop();
     if (this.splitLogWorker != null) {
@@ -1426,6 +1433,7 @@ public class HRegionServer implements HR
     // Start Server.  This service is like leases in that it internally runs
     // a thread.
     this.server.start();
+    isRpcServerRunning = true;
     // Create the log splitting worker and start it
     this.splitLogWorker = new SplitLogWorker(this.zooKeeperWrapper,
         this.getConfiguration(), this.serverInfo.getServerName(),
@@ -3189,6 +3197,9 @@ public class HRegionServer implements HR
               LOG.info("vmInputArguments=" + runtime.getInputArguments());
             }
             HRegionServer hrs = constructRegionServer(regionServerClass, conf);
+            Preconditions.checkState(mainRegionServer == null,
+                "Main regionserver initialized twice");
+            mainRegionServer = hrs;
             startRegionServer(hrs);
           }
         } catch (Throwable t) {
@@ -3272,4 +3283,19 @@ public class HRegionServer implements HR
     return stopReason;
   }
 
+  /**
+   * Get the regionserver running in this JVM as part of the main method (mini-cluster RS
instances
+   * do not count), if the given address matches. This is used to "short-circuit" client
calls done
+   * by the Thrift handler within the regionserver to the same regionserver.
+   * @return the main region server in this JVM or null if the address does not match
+   */
+  public static HRegionInterface getMainRS(HServerAddress address) {
+    if (mainRegionServer != null && 
+        address.equals(mainRegionServer.serverInfo.getServerAddress()) &&
+        mainRegionServer.isRpcServerRunning) {
+      return mainRegionServer;
+    }
+    return null;
+  }
+
 }



Mime
View raw message