Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 93541C3AA for ; Thu, 12 Jul 2012 00:27:03 +0000 (UTC) Received: (qmail 40178 invoked by uid 500); 12 Jul 2012 00:27:03 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 40144 invoked by uid 500); 12 Jul 2012 00:27:03 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 40137 invoked by uid 99); 12 Jul 2012 00:27:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2012 00:27:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2012 00:27:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F2ED123889CB for ; Thu, 12 Jul 2012 00:26:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@hbase.apache.org From: mbautin@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120712002639.F2ED123889CB@eris.apache.org> 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 threadLocalProfilingData = new ThreadLocal (); + /** 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; + } + }