You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2013/06/25 20:38:15 UTC

svn commit: r1496578 - /hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java

Author: larsgeorge
Date: Tue Jun 25 18:38:14 2013
New Revision: 1496578

URL: http://svn.apache.org/r1496578
Log:
HBASE-8782 Thrift2 can not parse values when using framed transport (Hamed Madani)

Modified:
    hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java

Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java?rev=1496578&r1=1496577&r2=1496578&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java (original)
+++ hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java Tue Jun 25 18:38:14 2013
@@ -28,6 +28,7 @@ import static org.apache.hadoop.hbase.th
 import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultFromHBase;
 import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultsFromHBase;
 import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.scanFromThrift;
+import static org.apache.thrift.TBaseHelper.byteBufferToByteArray;
 
 import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
@@ -45,7 +46,6 @@ 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.client.Delete;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.HTablePool;
 import org.apache.hadoop.hbase.client.ResultScanner;
@@ -62,8 +62,8 @@ import org.apache.hadoop.hbase.thrift2.g
 import org.apache.thrift.TException;
 
 /**
- * This class is a glue object that connects Thrift RPC calls to the HBase client API primarily defined in the
- * HTableInterface.
+ * This class is a glue object that connects Thrift RPC calls to the HBase client API primarily
+ * defined in the HTableInterface.
  */
 @InterfaceAudience.Private
 public class ThriftHBaseServiceHandler implements THBaseService.Iface {
@@ -75,46 +75,41 @@ public class ThriftHBaseServiceHandler i
   // nextScannerId and scannerMap are used to manage scanner state
   // TODO: Cleanup thread for Scanners, Scanner id wrap
   private final AtomicInteger nextScannerId = new AtomicInteger(0);
-  private final Map<Integer, ResultScanner> scannerMap = new ConcurrentHashMap<Integer, ResultScanner>();
+  private final Map<Integer, ResultScanner> scannerMap =
+      new ConcurrentHashMap<Integer, ResultScanner>();
 
-  public static THBaseService.Iface newInstance(
-      Configuration conf, ThriftMetrics metrics) {
+  public static THBaseService.Iface newInstance(Configuration conf, ThriftMetrics metrics) {
     THBaseService.Iface handler = new ThriftHBaseServiceHandler(conf);
-    return (THBaseService.Iface) Proxy.newProxyInstance(
-        handler.getClass().getClassLoader(),
-        new Class[]{THBaseService.Iface.class},
-        new THBaseServiceMetricsProxy(handler, metrics));
+    return (THBaseService.Iface) Proxy.newProxyInstance(handler.getClass().getClassLoader(),
+      new Class[] { THBaseService.Iface.class }, new THBaseServiceMetricsProxy(handler, metrics));
   }
 
   private static class THBaseServiceMetricsProxy implements InvocationHandler {
     private final THBaseService.Iface handler;
     private final ThriftMetrics metrics;
 
-    private THBaseServiceMetricsProxy(
-        THBaseService.Iface handler, ThriftMetrics metrics) {
+    private THBaseServiceMetricsProxy(THBaseService.Iface handler, ThriftMetrics metrics) {
       this.handler = handler;
       this.metrics = metrics;
     }
 
     @Override
-    public Object invoke(Object proxy, Method m, Object[] args)
-        throws Throwable {
+    public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
       Object result;
       try {
         long start = now();
         result = m.invoke(handler, args);
-        int processTime = (int)(now() - start);
+        int processTime = (int) (now() - start);
         metrics.incMethodTime(m.getName(), processTime);
       } catch (InvocationTargetException e) {
         throw e.getTargetException();
       } catch (Exception e) {
-        throw new RuntimeException(
-            "unexpected invocation exception: " + e.getMessage());
+        throw new RuntimeException("unexpected invocation exception: " + e.getMessage());
       }
       return result;
     }
   }
-    
+
   private static long now() {
     return System.nanoTime();
   }
@@ -123,8 +118,8 @@ public class ThriftHBaseServiceHandler i
     htablePool = new HTablePool(conf, Integer.MAX_VALUE);
   }
 
-  private HTableInterface getTable(byte[] tableName) {
-    return htablePool.getTable(tableName);
+  private HTableInterface getTable(ByteBuffer tableName) {
+    return htablePool.getTable(byteBufferToByteArray(tableName));
   }
 
   private void closeTable(HTableInterface table) throws TIOError {
@@ -143,7 +138,6 @@ public class ThriftHBaseServiceHandler i
 
   /**
    * Assigns a unique ID to the scanner and adds the mapping to an internal HashMap.
-   * 
    * @param scanner to add
    * @return Id for this Scanner
    */
@@ -155,7 +149,6 @@ public class ThriftHBaseServiceHandler i
 
   /**
    * Returns the Scanner associated with the specified Id.
-   * 
    * @param id of the Scanner to get
    * @return a Scanner, or null if the Id is invalid
    */
@@ -165,7 +158,6 @@ public class ThriftHBaseServiceHandler i
 
   /**
    * Removes the scanner associated with the specified ID from the internal HashMap.
-   * 
    * @param id of the Scanner to remove
    * @return the removed Scanner, or <code>null</code> if the Id is invalid
    */
@@ -175,7 +167,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public boolean exists(ByteBuffer table, TGet get) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       return htable.exists(getFromThrift(get));
     } catch (IOException e) {
@@ -187,7 +179,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public TResult get(ByteBuffer table, TGet get) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       return resultFromHBase(htable.get(getFromThrift(get)));
     } catch (IOException e) {
@@ -199,7 +191,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public List<TResult> getMultiple(ByteBuffer table, List<TGet> gets) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       return resultsFromHBase(htable.get(getsFromThrift(gets)));
     } catch (IOException e) {
@@ -211,7 +203,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public void put(ByteBuffer table, TPut put) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       htable.put(putFromThrift(put));
     } catch (IOException e) {
@@ -222,11 +214,13 @@ public class ThriftHBaseServiceHandler i
   }
 
   @Override
-  public boolean checkAndPut(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value, TPut put)
-    throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
-    try {
-      return htable.checkAndPut(row.array(), family.array(), qualifier.array(), (value == null) ? null : value.array(), putFromThrift(put));
+  public boolean checkAndPut(ByteBuffer table, ByteBuffer row, ByteBuffer family,
+      ByteBuffer qualifier, ByteBuffer value, TPut put) throws TIOError, TException {
+    HTableInterface htable = getTable(table);
+    try {
+      return htable.checkAndPut(byteBufferToByteArray(row), byteBufferToByteArray(family),
+        byteBufferToByteArray(qualifier), (value == null) ? null : byteBufferToByteArray(value),
+        putFromThrift(put));
     } catch (IOException e) {
       throw getTIOError(e);
     } finally {
@@ -236,7 +230,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public void putMultiple(ByteBuffer table, List<TPut> puts) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       htable.put(putsFromThrift(puts));
     } catch (IOException e) {
@@ -248,7 +242,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public void deleteSingle(ByteBuffer table, TDelete deleteSingle) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       htable.delete(deleteFromThrift(deleteSingle));
     } catch (IOException e) {
@@ -259,8 +253,9 @@ public class ThriftHBaseServiceHandler i
   }
 
   @Override
-  public List<TDelete> deleteMultiple(ByteBuffer table, List<TDelete> deletes) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+  public List<TDelete> deleteMultiple(ByteBuffer table, List<TDelete> deletes) throws TIOError,
+      TException {
+    HTableInterface htable = getTable(table);
     try {
       htable.delete(deletesFromThrift(deletes));
     } catch (IOException e) {
@@ -272,15 +267,18 @@ public class ThriftHBaseServiceHandler i
   }
 
   @Override
-  public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family, ByteBuffer qualifier, ByteBuffer value,
-      TDelete deleteSingle) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+  public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family,
+      ByteBuffer qualifier, ByteBuffer value, TDelete deleteSingle) throws TIOError, TException {
+    HTableInterface htable = getTable(table);
 
     try {
       if (value == null) {
-        return htable.checkAndDelete(row.array(), family.array(), qualifier.array(), null, deleteFromThrift(deleteSingle));
+        return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family),
+          byteBufferToByteArray(qualifier), null, deleteFromThrift(deleteSingle));
       } else {
-        return htable.checkAndDelete(row.array(), family.array(), qualifier.array(), value.array(), deleteFromThrift(deleteSingle));
+        return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family),
+          byteBufferToByteArray(qualifier), byteBufferToByteArray(value),
+          deleteFromThrift(deleteSingle));
       }
     } catch (IOException e) {
       throw getTIOError(e);
@@ -291,7 +289,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public TResult increment(ByteBuffer table, TIncrement increment) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     try {
       return resultFromHBase(htable.increment(incrementFromThrift(increment)));
     } catch (IOException e) {
@@ -303,7 +301,7 @@ public class ThriftHBaseServiceHandler i
 
   @Override
   public int openScanner(ByteBuffer table, TScan scan) throws TIOError, TException {
-    HTableInterface htable = getTable(table.array());
+    HTableInterface htable = getTable(table);
     ResultScanner resultScanner = null;
     try {
       resultScanner = htable.getScanner(scanFromThrift(scan));
@@ -316,7 +314,8 @@ public class ThriftHBaseServiceHandler i
   }
 
   @Override
-  public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException {
+  public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError,
+      TIllegalArgument, TException {
     ResultScanner scanner = getScanner(scannerId);
     if (scanner == null) {
       TIllegalArgument ex = new TIllegalArgument();