Index: src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java (revision 1174376) +++ src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java (working copy) @@ -193,12 +193,12 @@ * Constructs an HBaseHandler object. * @throws IOException */ - HBaseHandler() + protected HBaseHandler() throws IOException { this(HBaseConfiguration.create()); } - HBaseHandler(final Configuration c) + protected HBaseHandler(final Configuration c) throws IOException { this.conf = c; admin = new HBaseAdmin(conf); Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision 1174376) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (working copy) @@ -288,6 +288,9 @@ private final RegionServerAccounting regionServerAccounting; + // reference to the Thrift Server. + volatile private HRegionThriftServer thriftServer; + /** * The server name the Master sees us as. Its made from the hostname the * master passes us, port, and server startcode. Gets set after registration @@ -602,6 +605,13 @@ HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, HConstants.DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD), this.threadWakeFrequency); + + // Create the thread for the ThriftServer. + if (conf.getBoolean("hbase.regionserver.export.thrift", false)) { + thriftServer = new HRegionThriftServer(this, conf); + thriftServer.start(); + LOG.info("Started Thrift API from Region Server."); + } } /** @@ -670,6 +680,7 @@ } } // Run shutdown. + if (this.thriftServer != null) this.thriftServer.shutdown(); this.leases.closeAfterLeasesExpire(); this.rpcServer.stop(); if (this.splitLogWorker != null) { Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java (revision 0) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java (revision 0) @@ -0,0 +1,229 @@ +/** + * Copyright 2011 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HRegionLocation; +import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.NotServingRegionException; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.thrift.ThriftServer; +import org.apache.hadoop.hbase.thrift.ThriftUtilities; +import org.apache.hadoop.hbase.thrift.generated.Hbase; +import org.apache.hadoop.hbase.thrift.generated.IOError; +import org.apache.hadoop.hbase.thrift.generated.TRowResult; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TCompactProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.server.TNonblockingServer; +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TThreadPoolServer; +import org.apache.thrift.transport.TFramedTransport; +import org.apache.thrift.transport.TNonblockingServerSocket; +import org.apache.thrift.transport.TNonblockingServerTransport; +import org.apache.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TServerTransport; +import org.apache.thrift.transport.TTransportFactory; + +/** + * HRegionThriftServer - this class starts up a Thrift server in the same + * JVM where the RegionServer is running. It inherits most of the + * functionality from the standard ThriftServer. This is good because + * we can maintain compatibility with applications that use the + * standard Thrift interface. For performance reasons, we can override + * methods to directly invoke calls into the HRegionServer and avoid the hop. + *
+ * This can be enabled with hbase.regionserver.export.thrift set to true.
+ */
+public class HRegionThriftServer extends Thread {
+
+ public static final Log LOG = LogFactory.getLog(HRegionThriftServer.class);
+ public static final int DEFAULT_LISTEN_PORT = 9090;
+
+ private HRegionServer rs;
+ private Configuration conf;
+
+ private int port;
+ private boolean nonblocking;
+ private String bindIpAddress;
+ private String transport;
+ private String protocol;
+ volatile private TServer tserver;
+
+ /**
+ * Create an instance of the glue object that connects the
+ * RegionServer with the standard ThriftServer implementation
+ */
+ HRegionThriftServer(HRegionServer regionServer, Configuration conf) {
+ this.rs = regionServer;
+ this.conf = conf;
+ }
+
+ /**
+ * Inherit the Handler from the standard ThriftServer. This allows us
+ * to use the default implementation for most calls. We override certain calls
+ * for performance reasons
+ */
+ private class HBaseHandlerRegion extends ThriftServer.HBaseHandler {
+
+ HBaseHandlerRegion(final Configuration conf) throws IOException {
+ super(conf);
+ initialize(conf);
+ }
+
+ // TODO: Override more methods to short-circuit for performance
+
+ /**
+ * Get a record. Short-circuit to get better performance.
+ */
+ @Override
+ public List