hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1297300 - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/regionserver/ main/java/org/apache/hadoop/hbase/thrift/ test/java/org/apache/hadoop/hbase/thrift/
Date Tue, 06 Mar 2012 00:00:37 GMT
Author: tedyu
Date: Tue Mar  6 00:00:36 2012
New Revision: 1297300

URL: http://svn.apache.org/viewvc?rev=1297300&view=rev
Log:
HBASE-5507 ThriftServerRunner.HbaseHandler.getRegionInfo() and getTableRegions() do not use
ByteBuffer correctly (Scott Chen)

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java?rev=1297300&r1=1297299&r2=1297300&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
Tue Mar  6 00:00:36 2012
@@ -19,6 +19,8 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
+import static org.apache.hadoop.hbase.thrift.ThriftServerRunner.HBaseHandler.toBytes;
+
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -119,8 +121,9 @@ public class HRegionThriftServer extends
                                                 long timestamp,
       Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
       try {
-        byte [] row = rowb.array();
-        HTable table = getTable(tableName.array());
+        byte[] row = toBytes(rowb);
+
+        HTable table = getTable(toBytes(tableName));
         HRegionLocation location = table.getRegionLocation(row, false);
         byte[] regionName = location.getRegionInfo().getRegionName();
 
@@ -130,11 +133,9 @@ public class HRegionThriftServer extends
           Result result = rs.get(regionName, get);
           return ThriftUtilities.rowResultFromHBase(result);
         }
-        ByteBuffer[] columnArr = columns.toArray(
-                                   new ByteBuffer[columns.size()]);
         Get get = new Get(row);
-        for(ByteBuffer column : columnArr) {
-          byte [][] famAndQf = KeyValue.parseColumn(column.array());
+        for(ByteBuffer column : columns) {
+          byte [][] famAndQf = KeyValue.parseColumn(toBytes(column));
           if (famAndQf.length == 1) {
             get.addFamily(famAndQf[0]);
           } else {

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java?rev=1297300&r1=1297299&r2=1297300&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java Tue Mar
 6 00:00:36 2012
@@ -585,7 +585,7 @@ public class ThriftServerRunner implemen
     throws IOError {
       try{
         List<HRegionInfo> hris =
-            this.getHBaseAdmin().getTableRegions(tableName.array());
+            this.getHBaseAdmin().getTableRegions(toBytes(tableName));
         List<TRegionInfo> regions = new ArrayList<TRegionInfo>();
 
         if (hris != null) {
@@ -606,6 +606,18 @@ public class ThriftServerRunner implemen
       }
     }
 
+    /**
+     * Convert ByteBuffer to byte array. Note that this cannot be replaced by
+     * Bytes.toBytes().
+     */
+    public static byte[] toBytes(ByteBuffer bb) {
+      byte[] result = new byte[bb.remaining()];
+      // Make a duplicate so the position doesn't change
+      ByteBuffer dup = bb.duplicate();
+      dup.get(result, 0, result.length);
+      return result;
+    }
+
     @Deprecated
     @Override
     public List<TCell> get(
@@ -1337,12 +1349,13 @@ public class ThriftServerRunner implemen
     public TRegionInfo getRegionInfo(ByteBuffer searchRow) throws IOError {
       try {
         HTable table = getTable(HConstants.META_TABLE_NAME);
+        byte[] row = toBytes(searchRow);
         Result startRowResult = table.getRowOrBefore(
-          searchRow.array(), HConstants.CATALOG_FAMILY);
+          row, HConstants.CATALOG_FAMILY);
 
         if (startRowResult == null) {
           throw new IOException("Cannot find row in .META., row="
-                                + Bytes.toStringBinary(searchRow.array()));
+                                + Bytes.toStringBinary(row));
         }
 
         // find region start and end keys
@@ -1351,7 +1364,7 @@ public class ThriftServerRunner implemen
         if (value == null || value.length == 0) {
           throw new IOException("HRegionInfo REGIONINFO was null or " +
                                 " empty in Meta for row="
-                                + Bytes.toStringBinary(searchRow.array()));
+                                + Bytes.toStringBinary(row));
         }
         HRegionInfo regionInfo = Writables.getHRegionInfo(value);
         TRegionInfo region = new TRegionInfo();

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java?rev=1297300&r1=1297299&r2=1297300&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java Tue Mar
 6 00:00:36 2012
@@ -429,6 +429,11 @@ public class TestThriftServer {
   public void doTestGetTableRegions() throws Exception {
     ThriftServerRunner.HBaseHandler handler =
       new ThriftServerRunner.HBaseHandler(UTIL.getConfiguration());
+    doTestGetTableRegions(handler);
+  }
+
+  public static void doTestGetTableRegions(Hbase.Iface handler)
+      throws Exception {
     handler.createTable(tableAname, getColumnDescriptors());
     int regionCount = handler.getTableRegions(tableAname).size();
     assertEquals("empty table should have only 1 region, " +

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java?rev=1297300&r1=1297299&r2=1297300&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java
Tue Mar  6 00:00:36 2012
@@ -87,15 +87,6 @@ public class TestThriftServerCmdLine {
             continue;
           }
           for (boolean specifyCompact : new boolean[] {false, true}) {
-            // TODO: We observed that when
-            // (specifyFramed, specifyCompact) == (true, false).
-            // The method getRegionInfo() gets a corrupted parameter. This may
-            // be a thrift bug that needs further investigation. In this test we
-            // temporarily exclude these cases to avoid test failures.
-            if ((specifyFramed == true || implType.isAlwaysFramed ) &&
-                specifyCompact == false) {
-              continue;
-            }
             parameters.add(new Object[]{implType, new Boolean(specifyFramed),
                 new Boolean(specifyBindIP), new Boolean(specifyCompact)});
           }
@@ -217,6 +208,7 @@ public class TestThriftServerCmdLine {
       Hbase.Client client = new Hbase.Client(prot);
       TestThriftServer.doTestTableCreateDrop(client);
       TestThriftServer.doTestGetRegionInfo(client);
+      TestThriftServer.doTestGetTableRegions(client);
     } finally {
       sock.close();
     }



Mime
View raw message