You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2012/12/22 00:39:31 UTC

svn commit: r1425198 [1/2] - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/filter/ main/java/org/apache/hadoop/hbase/io/ main/java/org/apache/hadoop/hbas...

Author: eclark
Date: Fri Dec 21 23:39:30 2012
New Revision: 1425198

URL: http://svn.apache.org/viewvc?rev=1425198&view=rev
Log:
HBASE-7186 Split Classes for Client/Server module split.

Added:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClientRPC.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServerRPC.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcClientEngine.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcServerEngine.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientEngine.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerEngine.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/UnknownProtocolException.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/BloomType.java
Removed:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcEngine.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcEngine.java
Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/filter/FirstKeyValueMatchingQualifiersFilter.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/LoadIncrementalHFiles.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessControlLists.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/BloomFilterFactory.java
    hbase/trunk/hbase-server/src/main/resources/hbase-default.xml
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestForceCacheImportantBlocks.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/RandomTimeoutRpcEngine.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestProtoBufRpc.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFiles.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/CreateRandomStoreFile.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/DataBlockEncodingTool.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/EncodedSeekPerformanceTest.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/HFileReadWriteTest.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksRead.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCacheOnWriteInSchema.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMultiColumnScanner.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScanWithBloomError.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSeekOptimizations.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransaction.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/util/LoadTestTool.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java Fri Dec 21 23:39:30 2012
@@ -35,8 +35,7 @@ import org.apache.hadoop.hbase.io.encodi
 import org.apache.hadoop.hbase.io.hfile.HFile;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ColumnFamilySchema;
-import org.apache.hadoop.hbase.regionserver.StoreFile;
-import org.apache.hadoop.hbase.regionserver.StoreFile.BloomType;
+import org.apache.hadoop.hbase.regionserver.BloomType;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.WritableComparable;
@@ -164,7 +163,7 @@ public class HColumnDescriptor implement
   /**
    * Default setting for whether or not to use bloomfilters.
    */
-  public static final String DEFAULT_BLOOMFILTER = StoreFile.BloomType.NONE.toString();
+  public static final String DEFAULT_BLOOMFILTER = BloomType.NONE.toString();
 
   /**
    * Default setting for whether to cache bloom filter blocks on write if block
@@ -408,7 +407,7 @@ public class HColumnDescriptor implement
     setEncodeOnDisk(encodeOnDisk);
     setDataBlockEncoding(DataBlockEncoding.
         valueOf(dataBlockEncoding.toUpperCase()));
-    setBloomFilterType(StoreFile.BloomType.
+    setBloomFilterType(BloomType.
       valueOf(bloomFilter.toUpperCase()));
     setBlocksize(blocksize);
     setScope(scope);
@@ -760,19 +759,19 @@ public class HColumnDescriptor implement
   /**
    * @return bloom filter type used for new StoreFiles in ColumnFamily
    */
-  public StoreFile.BloomType getBloomFilterType() {
+  public BloomType getBloomFilterType() {
     String n = getValue(BLOOMFILTER);
     if (n == null) {
       n = DEFAULT_BLOOMFILTER;
     }
-    return StoreFile.BloomType.valueOf(n.toUpperCase());
+    return BloomType.valueOf(n.toUpperCase());
   }
 
   /**
    * @param bt bloom filter type
    * @return this (for chained invocation)
    */
-  public HColumnDescriptor setBloomFilterType(final StoreFile.BloomType bt) {
+  public HColumnDescriptor setBloomFilterType(final BloomType bt) {
     return setValue(BLOOMFILTER, bt.toString());
   }
 

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java Fri Dec 21 23:39:30 2012
@@ -33,16 +33,12 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.KeyValue.KVComparator;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.FSTableDescriptors;
 import org.apache.hadoop.hbase.util.JenkinsHash;
 import org.apache.hadoop.hbase.util.MD5Hash;
 import org.apache.hadoop.hbase.util.Pair;
@@ -560,54 +556,6 @@ public class HRegionInfo implements Comp
        Bytes.equals(endKey, HConstants.EMPTY_BYTE_ARRAY));
   }
 
-  /**
-   * @return the tableDesc
-   * @deprecated Do not use; expensive call
-   *         use HRegionInfo.getTableNameAsString() in place of
-   *         HRegionInfo.getTableDesc().getNameAsString()
-   */
-   @Deprecated
-  public HTableDescriptor getTableDesc() {
-    Configuration c = HBaseConfiguration.create();
-    c.set("fs.defaultFS", c.get(HConstants.HBASE_DIR));
-    c.set("fs.default.name", c.get(HConstants.HBASE_DIR));
-    FileSystem fs;
-    try {
-      fs = FileSystem.get(c);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-    FSTableDescriptors fstd =
-      new FSTableDescriptors(fs, new Path(c.get(HConstants.HBASE_DIR)));
-    try {
-      return fstd.get(this.tableName);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  /**
-   * @param newDesc new table descriptor to use
-   * @deprecated Do not use; expensive call
-   */
-  @Deprecated
-  public void setTableDesc(HTableDescriptor newDesc) {
-    Configuration c = HBaseConfiguration.create();
-    FileSystem fs;
-    try {
-      fs = FileSystem.get(c);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-    FSTableDescriptors fstd =
-      new FSTableDescriptors(fs, new Path(c.get(HConstants.HBASE_DIR)));
-    try {
-      fstd.add(newDesc);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
   /** @return true if this is the root region */
   public boolean isRootRegion() {
     return Bytes.equals(tableName, HRegionInfo.ROOT_REGIONINFO.getTableName());

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java Fri Dec 21 23:39:30 2012
@@ -72,7 +72,7 @@ import org.apache.hadoop.hbase.ZooKeeper
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitorBase;
 import org.apache.hadoop.hbase.client.coprocessor.Batch;
-import org.apache.hadoop.hbase.ipc.HBaseRPC;
+import org.apache.hadoop.hbase.ipc.HBaseClientRPC;
 import org.apache.hadoop.hbase.ipc.VersionedProtocol;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.protobuf.RequestConverter;
@@ -242,7 +242,7 @@ public class HConnectionManager {
    * @param stopProxy
    *          Shuts down all the proxy's put up to cluster members including to
    *          cluster HMaster. Calls
-   *          {@link HBaseRPC#stopProxy(org.apache.hadoop.hbase.ipc.VersionedProtocol)}
+   *          {@link HBaseClientRPC#stopProxy(org.apache.hadoop.hbase.ipc.VersionedProtocol)}
    *          .
    */
   public static void deleteConnection(Configuration conf, boolean stopProxy) {
@@ -709,16 +709,16 @@ public class HConnectionManager {
 
         InetSocketAddress isa =
           new InetSocketAddress(sn.getHostname(), sn.getPort());
-        MasterProtocol tryMaster = (MasterProtocol) HBaseRPC.getProxy(
-          masterProtocolState.protocolClass,
-          masterProtocolState.version,
-          isa, this.conf,this.rpcTimeout);
+        MasterProtocol tryMaster = (MasterProtocol) HBaseClientRPC.getProxy(
+            masterProtocolState.protocolClass,
+            masterProtocolState.version,
+            isa, this.conf, this.rpcTimeout);
 
         if (tryMaster.isMasterRunning(
             null, RequestConverter.buildIsMasterRunningRequest()).getIsMasterRunning()) {
           return tryMaster;
         } else {
-          HBaseRPC.stopProxy(tryMaster);
+          HBaseClientRPC.stopProxy(tryMaster);
           String msg = "Can create a proxy to master, but it is not running";
           LOG.info(msg);
           throw new MasterNotRunningException(msg);
@@ -1380,7 +1380,7 @@ public class HConnectionManager {
               // Only create isa when we need to.
               InetSocketAddress address = new InetSocketAddress(hostname, port);
               // definitely a cache miss. establish an RPC for this RS
-              server = HBaseRPC.waitForProxy(
+              server = HBaseClientRPC.waitForProxy(
                   protocolClass, version, address, this.conf,
                   this.maxRPCAttempts, this.rpcTimeout, this.rpcTimeout);
               protocols.put(protocol, server);
@@ -1595,7 +1595,7 @@ public class HConnectionManager {
       synchronized (masterAndZKLock) {
         if (!isKeepAliveMasterConnectedAndRunning(protocolState)) {
           if (protocolState.protocol != null) {
-            HBaseRPC.stopProxy(protocolState.protocol);
+            HBaseClientRPC.stopProxy(protocolState.protocol);
           }
           protocolState.protocol = null;
           protocolState.protocol = createMasterWithRetries(protocolState);
@@ -1671,7 +1671,7 @@ public class HConnectionManager {
     private void closeMasterProtocol(MasterProtocolState protocolState) {
       if (protocolState.protocol != null){
         LOG.info("Closing master protocol: " + protocolState.protocolClass.getName());
-        HBaseRPC.stopProxy(protocolState.protocol);
+        HBaseClientRPC.stopProxy(protocolState.protocol);
         protocolState.protocol = null;
       }
       protocolState.userCount = 0;
@@ -2252,7 +2252,7 @@ public class HConnectionManager {
         closeMaster();
         for (Map<String, VersionedProtocol> i : servers.values()) {
           for (VersionedProtocol server: i.values()) {
-            HBaseRPC.stopProxy(server);
+            HBaseClientRPC.stopProxy(server);
           }
         }
       }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java Fri Dec 21 23:39:30 2012
@@ -33,8 +33,7 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.hbase.DoNotRetryIOException;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionLocation;
-import org.apache.hadoop.hbase.client.ClientProtocol;
-import org.apache.hadoop.hbase.ipc.HBaseRPC;
+import org.apache.hadoop.hbase.ipc.HBaseClientRPC;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.ipc.RemoteException;
 
@@ -113,12 +112,12 @@ public abstract class ServerCallable<T> 
   }
 
   public void beforeCall() {
-    HBaseRPC.setRpcTimeout(this.callTimeout);
+    HBaseClientRPC.setRpcTimeout(this.callTimeout);
     this.startTime = System.currentTimeMillis();
   }
 
   public void afterCall() {
-    HBaseRPC.resetRpcTimeout();
+    HBaseClientRPC.resetRpcTimeout();
     this.endTime = System.currentTimeMillis();
   }
 

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/filter/FirstKeyValueMatchingQualifiersFilter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/filter/FirstKeyValueMatchingQualifiersFilter.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/filter/FirstKeyValueMatchingQualifiersFilter.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/filter/FirstKeyValueMatchingQualifiersFilter.java Fri Dec 21 23:39:30 2012
@@ -18,20 +18,17 @@
 
 package org.apache.hadoop.hbase.filter;
 
-import java.util.Collections;
-import java.util.Set;
-import java.util.TreeSet;
-
+import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.hbase.DeserializationException;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.mapreduce.RowCounter;
 import org.apache.hadoop.hbase.protobuf.generated.FilterProtos;
 import org.apache.hadoop.hbase.util.Bytes;
 
-import com.google.protobuf.ByteString;
-import com.google.protobuf.InvalidProtocolBufferException;
+import java.util.Set;
+import java.util.TreeSet;
 
 /**
  * The filter looks for the given columns in KeyValue. Once there is a match for

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java Fri Dec 21 23:39:30 2012
@@ -178,8 +178,10 @@ public class HbaseObjectWritable impleme
     addToMap(Integer.class, code++);
     addToMap(Integer[].class, code++);
 
-    addToMap(HRegion.class, code++);
-    addToMap(HRegion[].class, code++);
+    //HRegion shouldn't be pushed across the wire.
+    code++; //addToMap(HRegion.class, code++);
+    code++; //addToMap(HRegion[].class, code++);
+
     addToMap(HRegionInfo.class, code++);
     addToMap(HRegionInfo[].class, code++);
     code++; // Removed

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java Fri Dec 21 23:39:30 2012
@@ -28,6 +28,7 @@ import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Method;
 import java.net.ConnectException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
@@ -41,6 +42,7 @@ import java.util.LinkedList;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
@@ -106,6 +108,8 @@ public class HBaseClient {
   public static final Log LOG = LogFactory
       .getLog("org.apache.hadoop.ipc.HBaseClient");
   protected final PoolMap<ConnectionId, Connection> connections;
+  private static final Map<String, Method> methodInstances =
+      new ConcurrentHashMap<String, Method>();
 
   protected int counter;                            // counter for call ids
   protected final AtomicBoolean running = new AtomicBoolean(true); // if client runs
@@ -959,6 +963,24 @@ public class HBaseClient {
       }
     }
 
+
+    private Method getMethod(Class<? extends VersionedProtocol> protocol,
+                             String methodName) {
+      Method method = methodInstances.get(methodName);
+      if (method != null) {
+        return method;
+      }
+      Method[] methods = protocol.getMethods();
+      for (Method m : methods) {
+        if (m.getName().equals(methodName)) {
+          m.setAccessible(true);
+          methodInstances.put(methodName, m);
+          return m;
+        }
+      }
+      return null;
+    }
+
     /* Receive a response.
      * Because only one receiver, so no synchronization on in.
      */
@@ -990,9 +1012,9 @@ public class HBaseClient {
         if (status == Status.SUCCESS) {
           Message rpcResponseType;
           try {
-            rpcResponseType = ProtobufRpcEngine.Invoker.getReturnProtoType(
-                ProtobufRpcEngine.Server.getMethod(remoteId.getProtocol(),
-                    call.param.getMethodName()));
+            rpcResponseType = ProtobufRpcClientEngine.Invoker.getReturnProtoType(
+                getMethod(remoteId.getProtocol(),
+                          call.param.getMethodName()));
           } catch (Exception e) {
             throw new RuntimeException(e); //local exception
           }

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClientRPC.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClientRPC.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClientRPC.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClientRPC.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,294 @@
+/**
+ *
+ * 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.ipc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.client.RetriesExhaustedException;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.net.NetUtils;
+import org.apache.hadoop.util.ReflectionUtils;
+
+import javax.net.SocketFactory;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Proxy;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.SocketTimeoutException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An RPC implementation. This class provides the client side implementation.
+ */
+@InterfaceAudience.Private
+public class HBaseClientRPC {
+
+  protected static final Log LOG =
+      LogFactory.getLog("org.apache.hadoop.ipc.HBaseClientRPC");
+
+  // cache of RpcEngines by protocol
+  private static final Map<Class, RpcClientEngine> PROTOCOL_ENGINES
+      = new HashMap<Class, RpcClientEngine>();
+  /**
+   * Configuration key for the {@link org.apache.hadoop.hbase.ipc.RpcClientEngine} implementation
+   * to load to handle connection protocols.  Handlers for individual protocols can be
+   * configured using {@code "hbase.rpc.client.engine." + protocol.class.name}.
+   */
+  public static final String RPC_ENGINE_PROP = "hbase.rpc.client.engine";
+  // track what RpcEngine is used by a proxy class, for stopProxy()
+  private static final Map<Class, RpcClientEngine> PROXY_ENGINES
+      = new HashMap<Class, RpcClientEngine>();
+  // thread-specific RPC timeout, which may override that of RpcEngine
+  private static ThreadLocal<Integer> rpcTimeout = new ThreadLocal<Integer>() {
+    @Override
+    protected Integer initialValue() {
+      return HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
+    }
+  };
+
+  static long getProtocolVersion(Class<? extends VersionedProtocol> protocol)
+      throws NoSuchFieldException, IllegalAccessException {
+    Field versionField = protocol.getField("VERSION");
+    versionField.setAccessible(true);
+    return versionField.getLong(protocol);
+  }
+
+  // set a protocol to use a non-default RpcEngine
+  static void setProtocolEngine(Configuration conf,
+                                Class protocol, Class engine) {
+    conf.setClass(RPC_ENGINE_PROP + "." + protocol.getName(), engine, RpcClientEngine.class);
+  }
+
+  // return the RpcEngine configured to handle a protocol
+  static synchronized RpcClientEngine getProtocolEngine(Class protocol,
+                                                        Configuration conf) {
+    RpcClientEngine engine = PROTOCOL_ENGINES.get(protocol);
+    if (engine == null) {
+      // check for a configured default engine
+      Class<?> defaultEngine =
+          conf.getClass(RPC_ENGINE_PROP, ProtobufRpcClientEngine.class);
+
+      // check for a per interface override
+      Class<?> impl = conf.getClass(RPC_ENGINE_PROP + "." + protocol.getName(),
+          defaultEngine);
+      LOG.debug("Using " + impl.getName() + " for " + protocol.getName());
+      engine = (RpcClientEngine) ReflectionUtils.newInstance(impl, conf);
+      if (protocol.isInterface())
+        PROXY_ENGINES.put(Proxy.getProxyClass(protocol.getClassLoader(),
+            protocol),
+            engine);
+      PROTOCOL_ENGINES.put(protocol, engine);
+    }
+    return engine;
+  }
+
+  // return the RpcEngine that handles a proxy object
+  private static synchronized RpcClientEngine getProxyEngine(Object proxy) {
+    return PROXY_ENGINES.get(proxy.getClass());
+  }
+
+  /**
+   * @param protocol      protocol interface
+   * @param clientVersion which client version we expect
+   * @param addr          address of remote service
+   * @param conf          configuration
+   * @param maxAttempts   max attempts
+   * @param rpcTimeout    timeout for each RPC
+   * @param timeout       timeout in milliseconds
+   * @return proxy
+   * @throws java.io.IOException e
+   */
+  @SuppressWarnings("unchecked")
+  public static VersionedProtocol waitForProxy(Class protocol,
+                                               long clientVersion,
+                                               InetSocketAddress addr,
+                                               Configuration conf,
+                                               int maxAttempts,
+                                               int rpcTimeout,
+                                               long timeout
+  ) throws IOException {
+    // HBase does limited number of reconnects which is different from hadoop.
+    long startTime = System.currentTimeMillis();
+    IOException ioe;
+    int reconnectAttempts = 0;
+    while (true) {
+      try {
+        return getProxy(protocol, clientVersion, addr, conf, rpcTimeout);
+      } catch (SocketTimeoutException te) {  // namenode is busy
+       LOG.info("Problem connecting to server: " + addr);
+        ioe = te;
+      } catch (IOException ioex) {
+        // We only handle the ConnectException.
+        ConnectException ce = null;
+        if (ioex instanceof ConnectException) {
+          ce = (ConnectException) ioex;
+          ioe = ce;
+        } else if (ioex.getCause() != null
+            && ioex.getCause() instanceof ConnectException) {
+          ce = (ConnectException) ioex.getCause();
+          ioe = ce;
+        } else if (ioex.getMessage().toLowerCase()
+            .contains("connection refused")) {
+          ce = new ConnectException(ioex.getMessage());
+          ioe = ce;
+        } else {
+          // This is the exception we can't handle.
+          ioe = ioex;
+        }
+        if (ce != null) {
+          handleConnectionException(++reconnectAttempts, maxAttempts, protocol,
+              addr, ce);
+        }
+      }
+      // check if timed out
+      if (System.currentTimeMillis() - timeout >= startTime) {
+        throw ioe;
+      }
+
+      // wait for retry
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException ie) {
+        // IGNORE
+      }
+    }
+  }
+
+  /**
+   * @param retries    current retried times.
+   * @param maxAttmpts max attempts
+   * @param protocol   protocol interface
+   * @param addr       address of remote service
+   * @param ce         ConnectException
+   * @throws org.apache.hadoop.hbase.client.RetriesExhaustedException
+   *
+   */
+  private static void handleConnectionException(int retries,
+                                                int maxAttmpts,
+                                                Class<?> protocol,
+                                                InetSocketAddress addr,
+                                                ConnectException ce)
+      throws RetriesExhaustedException {
+    if (maxAttmpts >= 0 && retries >= maxAttmpts) {
+      LOG.info("Server at " + addr + " could not be reached after "
+          + maxAttmpts + " tries, giving up.");
+      throw new RetriesExhaustedException("Failed setting up proxy " + protocol
+          + " to " + addr.toString() + " after attempts=" + maxAttmpts, ce);
+    }
+  }
+
+  /**
+   * Construct a client-side proxy object that implements the named protocol,
+   * talking to a server at the named address.
+   *
+   * @param protocol      interface
+   * @param clientVersion version we are expecting
+   * @param addr          remote address
+   * @param conf          configuration
+   * @param factory       socket factory
+   * @param rpcTimeout    timeout for each RPC
+   * @return proxy
+   * @throws java.io.IOException e
+   */
+  public static VersionedProtocol getProxy(Class<? extends VersionedProtocol> protocol,
+                                           long clientVersion,
+                                           InetSocketAddress addr,
+                                           Configuration conf,
+                                           SocketFactory factory,
+                                           int rpcTimeout) throws IOException {
+    return getProxy(protocol, clientVersion, addr,
+        User.getCurrent(), conf, factory, rpcTimeout);
+  }
+
+  /**
+   * Construct a client-side proxy object that implements the named protocol,
+   * talking to a server at the named address.
+   *
+   * @param protocol      interface
+   * @param clientVersion version we are expecting
+   * @param addr          remote address
+   * @param ticket        ticket
+   * @param conf          configuration
+   * @param factory       socket factory
+   * @param rpcTimeout    timeout for each RPC
+   * @return proxy
+   * @throws java.io.IOException e
+   */
+  public static VersionedProtocol getProxy(
+      Class<? extends VersionedProtocol> protocol,
+      long clientVersion, InetSocketAddress addr, User ticket,
+      Configuration conf, SocketFactory factory, int rpcTimeout)
+      throws IOException {
+    RpcClientEngine engine = getProtocolEngine(protocol, conf);
+    VersionedProtocol proxy = engine
+        .getProxy(protocol, clientVersion, addr, ticket, conf, factory,
+            Math.min(rpcTimeout, getRpcTimeout()));
+    return proxy;
+  }
+
+  /**
+   * Construct a client-side proxy object with the default SocketFactory
+   *
+   * @param protocol      interface
+   * @param clientVersion version we are expecting
+   * @param addr          remote address
+   * @param conf          configuration
+   * @param rpcTimeout    timeout for each RPC
+   * @return a proxy instance
+   * @throws java.io.IOException e
+   */
+  public static VersionedProtocol getProxy(
+      Class<? extends VersionedProtocol> protocol,
+      long clientVersion, InetSocketAddress addr, Configuration conf,
+      int rpcTimeout)
+      throws IOException {
+
+    return getProxy(protocol, clientVersion, addr, conf, NetUtils
+        .getDefaultSocketFactory(conf), rpcTimeout);
+  }
+
+  /**
+   * Stop this proxy and release its invoker's resource
+   *
+   * @param proxy the proxy to be stopped
+   */
+  public static void stopProxy(VersionedProtocol proxy) {
+    if (proxy != null) {
+      getProxyEngine(proxy).stopProxy(proxy);
+    }
+  }
+
+  public static void setRpcTimeout(int t) {
+    rpcTimeout.set(t);
+  }
+
+  public static int getRpcTimeout() {
+    return rpcTimeout.get();
+  }
+
+  public static void resetRpcTimeout() {
+    rpcTimeout.remove();
+  }
+}

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServerRPC.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServerRPC.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServerRPC.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/HBaseServerRPC.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,173 @@
+/**
+ *
+ * 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.ipc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.ReflectionUtils;
+
+import java.io.IOException;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A simple RPC mechanism.
+ *
+ * This is a local hbase copy of the hadoop RPC so we can do things like
+ * address HADOOP-414 for hbase-only and try other hbase-specific
+ * optimizations.  Class has been renamed to avoid confusing it w/ hadoop
+ * versions.
+ * <p>
+ *
+ *
+ * A <i>protocol</i> is a Java interface.  All parameters and return types must
+ * be Protobuf objects.
+ * All methods in the protocol should throw only IOException.  No field data of
+ * the protocol instance is transmitted.
+ *
+ * This class provides the server side implementation.
+ */
+@InterfaceAudience.Private
+public class HBaseServerRPC {
+  // Leave this out in the hadoop ipc package but keep class name.  Do this
+  // so that we dont' get the logging of this class's invocations by doing our
+  // blanket enabling DEBUG on the o.a.h.h. package.
+  protected static final Log LOG =
+    LogFactory.getLog("org.apache.hadoop.ipc.HBaseServerRPC");
+
+  // cache of RpcEngines by protocol
+  private static final Map<Class, RpcServerEngine> PROTOCOL_ENGINES
+      = new HashMap<Class, RpcServerEngine>();
+
+  /**
+   * Configuration key for the {@link org.apache.hadoop.hbase.ipc.RpcServerEngine} implementation to
+   * load to handle connection protocols.  Handlers for individual protocols can be
+   * configured using {@code "hbase.rpc.server.engine." + protocol.class.name}.
+   */
+  public static final String RPC_ENGINE_PROP = "hbase.rpc.server.engine";
+  // track what RpcEngine is used by a proxy class, for stopProxy()
+  private static final Map<Class, RpcServerEngine> PROXY_ENGINES
+      = new HashMap<Class, RpcServerEngine>();
+
+  private HBaseServerRPC() {
+    super();
+  }                                  // no public ctor
+
+
+  // set a protocol to use a non-default RpcEngine
+  static void setProtocolEngine(Configuration conf,
+                                Class protocol, Class engine) {
+    conf.setClass(RPC_ENGINE_PROP + "." + protocol.getName(), engine, RpcServerEngine.class);
+  }
+
+  // return the RpcEngine configured to handle a protocol
+  static synchronized RpcServerEngine getProtocolEngine(Class protocol,
+                                                        Configuration conf) {
+    RpcServerEngine engine = PROTOCOL_ENGINES.get(protocol);
+    if (engine == null) {
+      // check for a configured default engine
+      Class<?> defaultEngine =
+          conf.getClass(RPC_ENGINE_PROP, ProtobufRpcServerEngine.class);
+
+      // check for a per interface override
+      Class<?> impl = conf.getClass(RPC_ENGINE_PROP + "." + protocol.getName(),
+          defaultEngine);
+      LOG.debug("Using " + impl.getName() + " for " + protocol.getName());
+      engine = (RpcServerEngine) ReflectionUtils.newInstance(impl, conf);
+      if (protocol.isInterface())
+        PROXY_ENGINES.put(Proxy.getProxyClass(protocol.getClassLoader(),
+            protocol),
+            engine);
+      PROTOCOL_ENGINES.put(protocol, engine);
+    }
+    return engine;
+  }
+
+  // return the RpcEngine that handles a proxy object
+  private static synchronized RpcServerEngine getProxyEngine(Object proxy) {
+    return PROXY_ENGINES.get(proxy.getClass());
+  }
+
+
+  /**
+   * Construct a server for a protocol implementation instance listening on a
+   * port and address.
+   *
+   * @param instance    instance
+   * @param bindAddress bind address
+   * @param port        port to bind to
+   * @param numHandlers number of handlers to start
+   * @param verbose     verbose flag
+   * @param conf        configuration
+   * @return Server
+   * @throws IOException e
+   */
+  public static RpcServer getServer(final Object instance,
+                                    final Class<?>[] ifaces,
+                                    final String bindAddress, final int port,
+                                    final int numHandlers,
+                                    int metaHandlerCount,
+                                    final boolean verbose,
+                                    Configuration conf,
+                                    int highPriorityLevel)
+      throws IOException {
+    return getServer(instance.getClass(),
+        instance,
+        ifaces,
+        bindAddress,
+        port,
+        numHandlers,
+        metaHandlerCount,
+        verbose,
+        conf,
+        highPriorityLevel);
+  }
+
+  /**
+   * Construct a server for a protocol implementation instance.
+   */
+  public static RpcServer getServer(Class protocol,
+                                    final Object instance,
+                                    final Class<?>[] ifaces,
+                                    String bindAddress,
+                                    int port,
+                                    final int numHandlers,
+                                    int metaHandlerCount,
+                                    final boolean verbose,
+                                    Configuration conf,
+                                    int highPriorityLevel)
+      throws IOException {
+    return getProtocolEngine(protocol, conf)
+        .getServer(protocol,
+            instance,
+            ifaces,
+            bindAddress,
+            port,
+            numHandlers,
+            metaHandlerCount,
+            verbose,
+            conf,
+            highPriorityLevel);
+  }
+
+}

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcClientEngine.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcClientEngine.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcClientEngine.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcClientEngine.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,194 @@
+/**
+ *
+ * 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.ipc;
+
+import com.google.protobuf.Message;
+import com.google.protobuf.ServiceException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.protobuf.generated.RPCProtos.RpcRequestBody;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.ipc.RemoteException;
+
+import javax.net.SocketFactory;
+import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ProtobufRpcClientEngine implements RpcClientEngine {
+
+  private static final Log LOG =
+      LogFactory.getLog("org.apache.hadoop.hbase.ipc.ProtobufRpcClientEngine");
+
+  ProtobufRpcClientEngine() {
+    super();
+  }
+
+  protected final static ClientCache CLIENTS = new ClientCache();
+  @Override
+  public VersionedProtocol getProxy(
+      Class<? extends VersionedProtocol> protocol, long clientVersion,
+      InetSocketAddress addr, User ticket, Configuration conf,
+      SocketFactory factory, int rpcTimeout) throws IOException {
+    final Invoker invoker = new Invoker(protocol, addr, ticket, conf, factory,
+        rpcTimeout);
+    return (VersionedProtocol) Proxy.newProxyInstance(
+        protocol.getClassLoader(), new Class[]{protocol}, invoker);
+  }
+
+  @Override
+  public void stopProxy(VersionedProtocol proxy) {
+    if (proxy!=null) {
+      ((Invoker)Proxy.getInvocationHandler(proxy)).close();
+    }
+  }
+
+  static class Invoker implements InvocationHandler {
+    private static final Map<String, Message> returnTypes =
+        new ConcurrentHashMap<String, Message>();
+    private Class<? extends VersionedProtocol> protocol;
+    private InetSocketAddress address;
+    private User ticket;
+    private HBaseClient client;
+    private boolean isClosed = false;
+    final private int rpcTimeout;
+    private final long clientProtocolVersion;
+
+    public Invoker(Class<? extends VersionedProtocol> protocol,
+                   InetSocketAddress addr, User ticket, Configuration conf,
+                   SocketFactory factory, int rpcTimeout) throws IOException {
+      this.protocol = protocol;
+      this.address = addr;
+      this.ticket = ticket;
+      this.client = CLIENTS.getClient(conf, factory);
+      this.rpcTimeout = rpcTimeout;
+      Long version = Invocation.PROTOCOL_VERSION.get(protocol);
+      if (version != null) {
+        this.clientProtocolVersion = version;
+      } else {
+        try {
+          this.clientProtocolVersion = HBaseClientRPC.getProtocolVersion(protocol);
+        } catch (NoSuchFieldException e) {
+          throw new RuntimeException("Exception encountered during " +
+              protocol, e);
+        } catch (IllegalAccessException e) {
+          throw new RuntimeException("Exception encountered during " +
+              protocol, e);
+        }
+      }
+    }
+
+    private RpcRequestBody constructRpcRequest(Method method,
+                                               Object[] params) throws ServiceException {
+      RpcRequestBody rpcRequest;
+      RpcRequestBody.Builder builder = RpcRequestBody.newBuilder();
+      builder.setMethodName(method.getName());
+      Message param;
+      int length = params.length;
+      if (length == 2) {
+        // RpcController + Message in the method args
+        // (generated code from RPC bits in .proto files have RpcController)
+        param = (Message)params[1];
+      } else if (length == 1) { // Message
+        param = (Message)params[0];
+      } else {
+        throw new ServiceException("Too many parameters for request. Method: ["
+            + method.getName() + "]" + ", Expected: 2, Actual: "
+            + params.length);
+      }
+      builder.setRequestClassName(param.getClass().getName());
+      builder.setRequest(param.toByteString());
+      builder.setClientProtocolVersion(clientProtocolVersion);
+      rpcRequest = builder.build();
+      return rpcRequest;
+    }
+
+    /**
+     * This is the client side invoker of RPC method. It only throws
+     * ServiceException, since the invocation proxy expects only
+     * ServiceException to be thrown by the method in case protobuf service.
+     *
+     * ServiceException has the following causes:
+     * <ol>
+     * <li>Exceptions encountered on the client side in this method are
+     * set as cause in ServiceException as is.</li>
+     * <li>Exceptions from the server are wrapped in RemoteException and are
+     * set as cause in ServiceException</li>
+     * </ol>
+     *
+     * Note that the client calling protobuf RPC methods, must handle
+     * ServiceException by getting the cause from the ServiceException. If the
+     * cause is RemoteException, then unwrap it to get the exception thrown by
+     * the server.
+     */
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args)
+        throws ServiceException {
+      long startTime = 0;
+      if (LOG.isDebugEnabled()) {
+        startTime = System.currentTimeMillis();
+      }
+
+      RpcRequestBody rpcRequest = constructRpcRequest(method, args);
+      Message val = null;
+      try {
+        val = client.call(rpcRequest, address, protocol, ticket, rpcTimeout);
+
+        if (LOG.isDebugEnabled()) {
+          long callTime = System.currentTimeMillis() - startTime;
+          if (LOG.isTraceEnabled()) LOG.trace("Call: " + method.getName() + " " + callTime);
+        }
+        return val;
+      } catch (Throwable e) {
+        if (e instanceof RemoteException) {
+          Throwable cause = ((RemoteException)e).unwrapRemoteException();
+          throw new ServiceException(cause);
+        }
+        throw new ServiceException(e);
+      }
+    }
+
+    synchronized protected void close() {
+      if (!isClosed) {
+        isClosed = true;
+        CLIENTS.stopClient(client);
+      }
+    }
+
+    static Message getReturnProtoType(Method method) throws Exception {
+      if (returnTypes.containsKey(method.getName())) {
+        return returnTypes.get(method.getName());
+      }
+
+      Class<?> returnType = method.getReturnType();
+      Method newInstMethod = returnType.getMethod("getDefaultInstance");
+      newInstMethod.setAccessible(true);
+      Message protoType = (Message) newInstMethod.invoke(null, (Object[]) null);
+      returnTypes.put(method.getName(), protoType);
+      return protoType;
+    }
+  }
+
+}

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcServerEngine.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcServerEngine.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcServerEngine.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ProtobufRpcServerEngine.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,381 @@
+/**
+ * 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.ipc;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.client.Operation;
+import org.apache.hadoop.hbase.monitoring.MonitoredRPCHandler;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.protobuf.generated.RPCProtos.RpcRequestBody;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.security.HBasePolicyProvider;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.hbase.security.token.AuthenticationTokenSecretManager;
+import org.apache.hadoop.security.authorize.ServiceAuthorizationManager;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import com.google.protobuf.Message;
+import com.google.protobuf.ServiceException;
+/**
+ * The {@link RpcServerEngine} implementation for ProtoBuf-based RPCs.
+ */
+@InterfaceAudience.Private
+class ProtobufRpcServerEngine implements RpcServerEngine {
+  private static final Log LOG =
+      LogFactory.getLog("org.apache.hadoop.hbase.ipc.ProtobufRpcServerEngine");
+
+  ProtobufRpcServerEngine() {
+    super();
+  }
+
+  @Override
+  public Server getServer(Class<? extends VersionedProtocol> protocol,
+                          Object instance, Class<?>[] ifaces, String bindAddress, int port,
+                          int numHandlers, int metaHandlerCount, boolean verbose,
+                          Configuration conf, int highPriorityLevel) throws IOException {
+    return new Server(instance, ifaces, conf, bindAddress, port, numHandlers,
+        metaHandlerCount, verbose, highPriorityLevel);
+  }
+
+
+  public static class Server extends HBaseServer {
+    boolean verbose;
+    Object instance;
+    Class<?> implementation;
+    private static final String WARN_RESPONSE_TIME =
+        "hbase.ipc.warn.response.time";
+    private static final String WARN_RESPONSE_SIZE =
+        "hbase.ipc.warn.response.size";
+
+    /** Default value for above params */
+    private static final int DEFAULT_WARN_RESPONSE_TIME = 10000; // milliseconds
+    private static final int DEFAULT_WARN_RESPONSE_SIZE = 100 * 1024 * 1024;
+
+    /** Names for suffixed metrics */
+    private static final String ABOVE_ONE_SEC_METRIC = ".aboveOneSec.";
+
+    private final int warnResponseTime;
+    private final int warnResponseSize;
+
+    private static String classNameBase(String className) {
+      String[] names = className.split("\\.", -1);
+      if (names == null || names.length == 0) {
+        return className;
+      }
+      return names[names.length-1];
+    }
+
+    public Server(Object instance, final Class<?>[] ifaces,
+                  Configuration conf, String bindAddress,  int port,
+                  int numHandlers, int metaHandlerCount, boolean verbose,
+                  int highPriorityLevel)
+        throws IOException {
+      super(bindAddress, port, numHandlers, metaHandlerCount,
+          conf, classNameBase(instance.getClass().getName()),
+          highPriorityLevel);
+      this.instance = instance;
+      this.implementation = instance.getClass();
+      this.verbose = verbose;
+
+      this.warnResponseTime = conf.getInt(WARN_RESPONSE_TIME,
+          DEFAULT_WARN_RESPONSE_TIME);
+      this.warnResponseSize = conf.getInt(WARN_RESPONSE_SIZE,
+          DEFAULT_WARN_RESPONSE_SIZE);
+      this.verbose = verbose;
+      this.instance = instance;
+      this.implementation = instance.getClass();
+    }
+    private static final Map<String, Message> methodArg =
+        new ConcurrentHashMap<String, Message>();
+    private static final Map<String, Method> methodInstances =
+        new ConcurrentHashMap<String, Method>();
+
+    private AuthenticationTokenSecretManager createSecretManager(){
+      if (!isSecurityEnabled ||
+          !(instance instanceof org.apache.hadoop.hbase.Server)) {
+        return null;
+      }
+      org.apache.hadoop.hbase.Server server =
+          (org.apache.hadoop.hbase.Server)instance;
+      Configuration conf = server.getConfiguration();
+      long keyUpdateInterval =
+          conf.getLong("hbase.auth.key.update.interval", 24*60*60*1000);
+      long maxAge =
+          conf.getLong("hbase.auth.token.max.lifetime", 7*24*60*60*1000);
+      return new AuthenticationTokenSecretManager(conf, server.getZooKeeper(),
+          server.getServerName().toString(), keyUpdateInterval, maxAge);
+    }
+
+    @Override
+    public void startThreads() {
+      AuthenticationTokenSecretManager mgr = createSecretManager();
+      if (mgr != null) {
+        setSecretManager(mgr);
+        mgr.start();
+      }
+      this.authManager = new ServiceAuthorizationManager();
+      HBasePolicyProvider.init(conf, authManager);
+
+      // continue with base startup
+      super.startThreads();
+    }
+
+    @Override
+    /**
+     * This is a server side method, which is invoked over RPC. On success
+     * the return response has protobuf response payload. On failure, the
+     * exception name and the stack trace are returned in the protobuf response.
+     */
+    public Message call(Class<? extends VersionedProtocol> protocol,
+                        RpcRequestBody rpcRequest, long receiveTime, MonitoredRPCHandler status)
+        throws IOException {
+      try {
+        String methodName = rpcRequest.getMethodName();
+        Method method = getMethod(protocol, methodName);
+        if (method == null) {
+          throw new UnknownProtocolException("Method " + methodName +
+              " doesn't exist in protocol " + protocol.getName());
+        }
+
+        /**
+         * RPCs for a particular interface (ie protocol) are done using a
+         * IPC connection that is setup using rpcProxy.
+         * The rpcProxy's has a declared protocol name that is
+         * sent form client to server at connection time.
+         */
+        //TODO: use the clientVersion to do protocol compatibility checks, and
+        //this could be used here to handle complex use cases like deciding
+        //which implementation of the protocol should be used to service the
+        //current request, etc. Ideally, we shouldn't land up in a situation
+        //where we need to support such a use case.
+        //For now the clientVersion field is simply ignored
+        long clientVersion = rpcRequest.getClientProtocolVersion();
+
+        if (verbose) {
+          LOG.info("Call: protocol name=" + protocol.getName() +
+              ", method=" + methodName);
+        }
+
+        status.setRPC(rpcRequest.getMethodName(),
+            new Object[]{rpcRequest.getRequest()}, receiveTime);
+        status.setRPCPacket(rpcRequest);
+        status.resume("Servicing call");
+        //get an instance of the method arg type
+        Message protoType = getMethodArgType(method);
+        Message param = protoType.newBuilderForType()
+            .mergeFrom(rpcRequest.getRequest()).build();
+        Message result;
+        Object impl = null;
+        if (protocol.isAssignableFrom(this.implementation)) {
+          impl = this.instance;
+        } else {
+          throw new UnknownProtocolException(protocol);
+        }
+
+        long startTime = System.currentTimeMillis();
+        if (method.getParameterTypes().length == 2) {
+          // RpcController + Message in the method args
+          // (generated code from RPC bits in .proto files have RpcController)
+          result = (Message)method.invoke(impl, null, param);
+        } else if (method.getParameterTypes().length == 1) {
+          // Message (hand written code usually has only a single argument)
+          result = (Message)method.invoke(impl, param);
+        } else {
+          throw new ServiceException("Too many parameters for method: ["
+              + method.getName() + "]" + ", allowed (at most): 2, Actual: "
+              + method.getParameterTypes().length);
+        }
+        int processingTime = (int) (System.currentTimeMillis() - startTime);
+        int qTime = (int) (startTime-receiveTime);
+        if (TRACELOG.isDebugEnabled()) {
+          TRACELOG.debug("Call #" + CurCall.get().id +
+              "; served=" + protocol.getSimpleName() + "#" + method.getName() +
+              ", queueTime=" + qTime +
+              ", processingTime=" + processingTime +
+              ", request=" + param.toString() +
+              " response=" + result.toString());
+        }
+        metrics.dequeuedCall(qTime);
+        metrics.processedCall(processingTime);
+
+        if (verbose) {
+          log("Return: "+result, LOG);
+        }
+        long responseSize = result.getSerializedSize();
+        // log any RPC responses that are slower than the configured warn
+        // response time or larger than configured warning size
+        boolean tooSlow = (processingTime > warnResponseTime
+            && warnResponseTime > -1);
+        boolean tooLarge = (responseSize > warnResponseSize
+            && warnResponseSize > -1);
+        if (tooSlow || tooLarge) {
+          // when tagging, we let TooLarge trump TooSmall to keep output simple
+          // note that large responses will often also be slow.
+          StringBuilder buffer = new StringBuilder(256);
+          buffer.append(methodName);
+          buffer.append("(");
+          buffer.append(param.getClass().getName());
+          buffer.append(")");
+          buffer.append(", client version="+clientVersion);
+          logResponse(new Object[]{rpcRequest.getRequest()},
+              methodName, buffer.toString(), (tooLarge ? "TooLarge" : "TooSlow"),
+              status.getClient(), startTime, processingTime, qTime,
+              responseSize);
+        }
+        return result;
+      } catch (InvocationTargetException e) {
+        Throwable target = e.getTargetException();
+        if (target instanceof IOException) {
+          throw (IOException)target;
+        }
+        if (target instanceof ServiceException) {
+          throw ProtobufUtil.getRemoteException((ServiceException)target);
+        }
+        IOException ioe = new IOException(target.toString());
+        ioe.setStackTrace(target.getStackTrace());
+        throw ioe;
+      } catch (Throwable e) {
+        if (!(e instanceof IOException)) {
+          LOG.error("Unexpected throwable object ", e);
+        }
+        IOException ioe = new IOException(e.toString());
+        ioe.setStackTrace(e.getStackTrace());
+        throw ioe;
+      }
+    }
+
+    static Method getMethod(Class<? extends VersionedProtocol> protocol,
+                            String methodName) {
+      Method method = methodInstances.get(methodName);
+      if (method != null) {
+        return method;
+      }
+      Method[] methods = protocol.getMethods();
+      for (Method m : methods) {
+        if (m.getName().equals(methodName)) {
+          m.setAccessible(true);
+          methodInstances.put(methodName, m);
+          return m;
+        }
+      }
+      return null;
+    }
+
+    static Message getMethodArgType(Method method) throws Exception {
+      Message protoType = methodArg.get(method.getName());
+      if (protoType != null) {
+        return protoType;
+      }
+
+      Class<?>[] args = method.getParameterTypes();
+      Class<?> arg;
+      if (args.length == 2) {
+        // RpcController + Message in the method args
+        // (generated code from RPC bits in .proto files have RpcController)
+        arg = args[1];
+      } else if (args.length == 1) {
+        arg = args[0];
+      } else {
+        //unexpected
+        return null;
+      }
+      //in the protobuf methods, args[1] is the only significant argument
+      Method newInstMethod = arg.getMethod("getDefaultInstance");
+      newInstMethod.setAccessible(true);
+      protoType = (Message) newInstMethod.invoke(null, (Object[]) null);
+      methodArg.put(method.getName(), protoType);
+      return protoType;
+    }
+    /**
+     * Logs an RPC response to the LOG file, producing valid JSON objects for
+     * client Operations.
+     * @param params The parameters received in the call.
+     * @param methodName The name of the method invoked
+     * @param call The string representation of the call
+     * @param tag  The tag that will be used to indicate this event in the log.
+     * @param clientAddress   The address of the client who made this call.
+     * @param startTime       The time that the call was initiated, in ms.
+     * @param processingTime  The duration that the call took to run, in ms.
+     * @param qTime           The duration that the call spent on the queue
+     *                        prior to being initiated, in ms.
+     * @param responseSize    The size in bytes of the response buffer.
+     */
+    void logResponse(Object[] params, String methodName, String call, String tag,
+                     String clientAddress, long startTime, int processingTime, int qTime,
+                     long responseSize)
+        throws IOException {
+      // for JSON encoding
+      ObjectMapper mapper = new ObjectMapper();
+      // base information that is reported regardless of type of call
+      Map<String, Object> responseInfo = new HashMap<String, Object>();
+      responseInfo.put("starttimems", startTime);
+      responseInfo.put("processingtimems", processingTime);
+      responseInfo.put("queuetimems", qTime);
+      responseInfo.put("responsesize", responseSize);
+      responseInfo.put("client", clientAddress);
+      responseInfo.put("class", instance.getClass().getSimpleName());
+      responseInfo.put("method", methodName);
+      if (params.length == 2 && instance instanceof HRegionServer &&
+          params[0] instanceof byte[] &&
+          params[1] instanceof Operation) {
+        // if the slow process is a query, we want to log its table as well
+        // as its own fingerprint
+        byte [] tableName =
+            HRegionInfo.parseRegionName((byte[]) params[0])[0];
+        responseInfo.put("table", Bytes.toStringBinary(tableName));
+        // annotate the response map with operation details
+        responseInfo.putAll(((Operation) params[1]).toMap());
+        // report to the log file
+        LOG.warn("(operation" + tag + "): " +
+            mapper.writeValueAsString(responseInfo));
+      } else if (params.length == 1 && instance instanceof HRegionServer &&
+          params[0] instanceof Operation) {
+        // annotate the response map with operation details
+        responseInfo.putAll(((Operation) params[0]).toMap());
+        // report to the log file
+        LOG.warn("(operation" + tag + "): " +
+            mapper.writeValueAsString(responseInfo));
+      } else {
+        // can't get JSON details, so just report call.toString() along with
+        // a more generic tag.
+        responseInfo.put("call", call);
+        LOG.warn("(response" + tag + "): " +
+            mapper.writeValueAsString(responseInfo));
+      }
+    }
+    protected static void log(String value, Log LOG) {
+      String v = value;
+      if (v != null && v.length() > 55)
+        v = v.substring(0, 55)+"...";
+      LOG.info(v);
+    }
+  }
+}

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientEngine.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientEngine.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientEngine.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcClientEngine.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,42 @@
+/**
+ *
+ * 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.ipc;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.security.User;
+
+import javax.net.SocketFactory;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+/** An RPC implementation for the client */
+@InterfaceAudience.Private
+public interface RpcClientEngine {
+  /** Construct a client-side proxy object. */
+  VersionedProtocol getProxy(Class<? extends VersionedProtocol> protocol,
+                             long clientVersion, InetSocketAddress addr,
+                             User ticket, Configuration conf,
+                             SocketFactory factory, int rpcTimeout) throws IOException;
+
+  /** Stop this proxy. */
+  void stopProxy(VersionedProtocol proxy);
+
+}

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerEngine.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerEngine.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerEngine.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerEngine.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.ipc;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+
+import java.io.IOException;
+
+/** An RPC implementation for the server. */
+@InterfaceAudience.Private
+interface RpcServerEngine {
+
+  /** Construct a server for a protocol implementation instance. */
+  RpcServer getServer(Class<? extends VersionedProtocol> protocol, Object instance,
+                       Class<?>[] ifaces, String bindAddress,
+                       int port, int numHandlers, int metaHandlerCount,
+                       boolean verbose, Configuration conf, int highPriorityLevel)
+      throws IOException;
+}

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/UnknownProtocolException.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/UnknownProtocolException.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/UnknownProtocolException.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/UnknownProtocolException.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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.ipc;
+
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+
+/**
+ * An error requesting an RPC protocol that the server is not serving.
+ */
+public class UnknownProtocolException extends DoNotRetryIOException {
+  private Class<?> protocol;
+
+  public UnknownProtocolException(String mesg) {
+    // required for unwrapping from a RemoteException
+    super(mesg);
+  }
+
+  public UnknownProtocolException(Class<?> protocol) {
+    this(protocol, "Server is not handling protocol "+protocol.getName());
+  }
+
+  public UnknownProtocolException(Class<?> protocol, String mesg) {
+    super(mesg);
+    this.protocol = protocol;
+  }
+
+  public Class getProtocol() {
+    return protocol;
+  }
+}

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/LoadIncrementalHFiles.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/LoadIncrementalHFiles.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/LoadIncrementalHFiles.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/LoadIncrementalHFiles.java Fri Dec 21 23:39:30 2012
@@ -71,9 +71,9 @@ import org.apache.hadoop.hbase.io.hfile.
 import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoderImpl;
 import org.apache.hadoop.hbase.io.hfile.HFileScanner;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.regionserver.BloomType;
 import org.apache.hadoop.hbase.regionserver.HStore;
 import org.apache.hadoop.hbase.regionserver.StoreFile;
-import org.apache.hadoop.hbase.regionserver.StoreFile.BloomType;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.util.Tool;

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Fri Dec 21 23:39:30 2012
@@ -83,11 +83,13 @@ import org.apache.hadoop.hbase.client.Re
 import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
 import org.apache.hadoop.hbase.executor.ExecutorService;
 import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorType;
-import org.apache.hadoop.hbase.ipc.HBaseRPC;
+import org.apache.hadoop.hbase.ipc.HBaseClientRPC;
 import org.apache.hadoop.hbase.ipc.HBaseServer;
+import org.apache.hadoop.hbase.ipc.HBaseServerRPC;
 import org.apache.hadoop.hbase.ipc.ProtocolSignature;
 import org.apache.hadoop.hbase.ipc.RpcServer;
 import org.apache.hadoop.hbase.ipc.ServerRpcController;
+import org.apache.hadoop.hbase.ipc.UnknownProtocolException;
 import org.apache.hadoop.hbase.master.balancer.BalancerChore;
 import org.apache.hadoop.hbase.master.balancer.ClusterStatusChore;
 import org.apache.hadoop.hbase.master.balancer.LoadBalancerFactory;
@@ -167,7 +169,6 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse;
 import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.ReportRSFatalErrorRequest;
 import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.ReportRSFatalErrorResponse;
-import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.replication.regionserver.Replication;
 import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -351,9 +352,9 @@ Server {
     }
     int numHandlers = conf.getInt("hbase.master.handler.count",
       conf.getInt("hbase.regionserver.handler.count", 25));
-    this.rpcServer = HBaseRPC.getServer(MasterMonitorProtocol.class, this,
-      new Class<?>[]{MasterMonitorProtocol.class,
-        MasterAdminProtocol.class, RegionServerStatusProtocol.class},
+    this.rpcServer = HBaseServerRPC.getServer(MasterMonitorProtocol.class, this,
+        new Class<?>[]{MasterMonitorProtocol.class,
+            MasterAdminProtocol.class, RegionServerStatusProtocol.class},
         initialIsa.getHostName(), // BindAddress is IP we got for this server.
         initialIsa.getPort(),
         numHandlers,
@@ -2347,7 +2348,7 @@ Server {
       String serviceName = call.getServiceName();
       String methodName = call.getMethodName();
       if (!coprocessorServiceHandlers.containsKey(serviceName)) {
-        throw new HBaseRPC.UnknownProtocolException(null,
+        throw new UnknownProtocolException(null,
             "No registered master coprocessor service found for name "+serviceName);
       }
 
@@ -2355,7 +2356,7 @@ Server {
       Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
       Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
       if (methodDesc == null) {
-        throw new HBaseRPC.UnknownProtocolException(service.getClass(),
+        throw new UnknownProtocolException(service.getClass(),
             "Unknown method "+methodName+" called on master service "+serviceName);
       }
 

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/BloomType.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/BloomType.java?rev=1425198&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/BloomType.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/BloomType.java Fri Dec 21 23:39:30 2012
@@ -0,0 +1,35 @@
+/**
+ *
+ * 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;
+
+public enum BloomType {
+  /**
+   * Bloomfilters disabled
+   */
+  NONE,
+  /**
+   * Bloom enabled with Table row as Key
+   */
+  ROW,
+  /**
+   * Bloom enabled with Table row & column (family+qualifier) as Key
+   */
+  ROWCOL
+}
\ No newline at end of file

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java Fri Dec 21 23:39:30 2012
@@ -106,9 +106,9 @@ import org.apache.hadoop.hbase.io.HeapSi
 import org.apache.hadoop.hbase.io.TimeRange;
 import org.apache.hadoop.hbase.io.hfile.BlockCache;
 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
-import org.apache.hadoop.hbase.ipc.HBaseRPC;
 import org.apache.hadoop.hbase.ipc.HBaseServer;
 import org.apache.hadoop.hbase.ipc.RpcCallContext;
+import org.apache.hadoop.hbase.ipc.UnknownProtocolException;
 import org.apache.hadoop.hbase.monitoring.MonitoredTask;
 import org.apache.hadoop.hbase.monitoring.TaskMonitor;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceCall;
@@ -4978,7 +4978,7 @@ public class HRegion implements HeapSize
     String serviceName = call.getServiceName();
     String methodName = call.getMethodName();
     if (!coprocessorServiceHandlers.containsKey(serviceName)) {
-      throw new HBaseRPC.UnknownProtocolException(null,
+      throw new UnknownProtocolException(null,
           "No registered coprocessor service found for name "+serviceName+
           " in region "+Bytes.toStringBinary(getRegionName()));
     }
@@ -4987,7 +4987,7 @@ public class HRegion implements HeapSize
     Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
     Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
     if (methodDesc == null) {
-      throw new HBaseRPC.UnknownProtocolException(service.getClass(),
+      throw new UnknownProtocolException(service.getClass(),
           "Unknown method "+methodName+" called on service "+serviceName+
               " in region "+Bytes.toStringBinary(getRegionName()));
     }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Fri Dec 21 23:39:30 2012
@@ -101,8 +101,11 @@ import org.apache.hadoop.hbase.filter.By
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.fs.HFileSystem;
 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
-import org.apache.hadoop.hbase.ipc.HBaseRPC;
 import org.apache.hadoop.hbase.ipc.HBaseRPCErrorHandler;
+import org.apache.hadoop.hbase.ipc.HBaseClientRPC;
+import org.apache.hadoop.hbase.ipc.HBaseRPCErrorHandler;
+import org.apache.hadoop.hbase.ipc.HBaseServerRPC;
+import org.apache.hadoop.hbase.ipc.MetricsHBaseServer;
 import org.apache.hadoop.hbase.ipc.ProtocolSignature;
 import org.apache.hadoop.hbase.ipc.RpcServer;
 import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
@@ -489,10 +492,10 @@ public class  HRegionServer implements C
       throw new IllegalArgumentException("Failed resolve of " + initialIsa);
     }
 
-    this.rpcServer = HBaseRPC.getServer(AdminProtocol.class, this,
-      new Class<?>[]{ClientProtocol.class,
-        AdminProtocol.class, HBaseRPCErrorHandler.class,
-        OnlineRegions.class},
+    this.rpcServer = HBaseServerRPC.getServer(AdminProtocol.class, this,
+        new Class<?>[]{ClientProtocol.class,
+            AdminProtocol.class, HBaseRPCErrorHandler.class,
+            OnlineRegions.class},
         initialIsa.getHostName(), // BindAddress is IP we got for this server.
         initialIsa.getPort(),
         conf.getInt("hbase.regionserver.handler.count", 10),
@@ -965,7 +968,7 @@ public class  HRegionServer implements C
 
     // Make sure the proxy is down.
     if (this.hbaseMaster != null) {
-      HBaseRPC.stopProxy(this.hbaseMaster);
+      HBaseClientRPC.stopProxy(this.hbaseMaster);
       this.hbaseMaster = null;
     }
     this.leases.close();
@@ -1773,7 +1776,7 @@ public class  HRegionServer implements C
       try {
         // Do initial RPC setup. The final argument indicates that the RPC
         // should retry indefinitely.
-        master = (RegionServerStatusProtocol) HBaseRPC.waitForProxy(
+        master = (RegionServerStatusProtocol) HBaseClientRPC.waitForProxy(
             RegionServerStatusProtocol.class, RegionServerStatusProtocol.VERSION,
             isa, this.conf, -1,
             this.rpcTimeout, this.rpcTimeout);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java Fri Dec 21 23:39:30 2012
@@ -92,21 +92,6 @@ import com.google.common.collect.Orderin
 public class StoreFile {
   static final Log LOG = LogFactory.getLog(StoreFile.class.getName());
 
-  public static enum BloomType {
-    /**
-     * Bloomfilters disabled
-     */
-    NONE,
-    /**
-     * Bloom enabled with Table row as Key
-     */
-    ROW,
-    /**
-     * Bloom enabled with Table row & column (family+qualifier) as Key
-     */
-    ROWCOL
-  }
-
   // Keys for fileinfo values in HFile
 
   /** Max Sequence ID in FileInfo */

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java Fri Dec 21 23:39:30 2012
@@ -279,7 +279,7 @@ public class StoreFileScanner implements
     boolean haveToSeek = true;
     if (useBloom) {
       // check ROWCOL Bloom filter first.
-      if (reader.getBloomFilterType() == StoreFile.BloomType.ROWCOL) {
+      if (reader.getBloomFilterType() == BloomType.ROWCOL) {
         haveToSeek = reader.passesGeneralBloomFilter(kv.getBuffer(),
             kv.getRowOffset(), kv.getRowLength(), kv.getBuffer(),
             kv.getQualifierOffset(), kv.getQualifierLength());

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessControlLists.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessControlLists.java?rev=1425198&r1=1425197&r2=1425198&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessControlLists.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessControlLists.java Fri Dec 21 23:39:30 2012
@@ -40,9 +40,9 @@ import org.apache.hadoop.hbase.client.Sc
 import org.apache.hadoop.hbase.io.HbaseObjectWritable;
 import org.apache.hadoop.hbase.io.compress.Compression;
 import org.apache.hadoop.hbase.master.MasterServices;
+import org.apache.hadoop.hbase.regionserver.BloomType;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.InternalScanner;
-import org.apache.hadoop.hbase.regionserver.StoreFile;
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.filter.RegexStringComparator;
 import org.apache.hadoop.hbase.filter.QualifierFilter;
@@ -98,7 +98,7 @@ public class AccessControlLists {
         new HColumnDescriptor(ACL_LIST_FAMILY,
             10, // Ten is arbitrary number.  Keep versions to help debugging.
             Compression.Algorithm.NONE.getName(), true, true, 8 * 1024,
-            HConstants.FOREVER, StoreFile.BloomType.NONE.toString(),
+            HConstants.FOREVER, BloomType.NONE.toString(),
             HConstants.REPLICATION_SCOPE_LOCAL));
   }