hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1297322 - in /hbase/branches/0.94/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 02:16:14 GMT
Author: tedyu
Date: Tue Mar  6 02:16:14 2012
New Revision: 1297322

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

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

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java?rev=1297322&r1=1297321&r2=1297322&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionThriftServer.java
Tue Mar  6 02:16:14 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;
@@ -117,8 +119,8 @@ 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();
 
@@ -128,11 +130,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/branches/0.94/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java?rev=1297322&r1=1297321&r2=1297322&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
Tue Mar  6 02:16:14 2012
@@ -569,7 +569,8 @@ public class ThriftServerRunner implemen
     public List<TRegionInfo> getTableRegions(ByteBuffer tableName)
     throws IOError {
       try{
-        List<HRegionInfo> hris = this.admin.getTableRegions(tableName.array());
+        List<HRegionInfo> hris =
+            this.admin.getTableRegions(toBytes(tableName));
         List<TRegionInfo> regions = new ArrayList<TRegionInfo>();
 
         if (hris != null) {
@@ -590,6 +591,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(
@@ -1321,8 +1334,9 @@ 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="
@@ -1335,7 +1349,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.toString(searchRow.array()));
+                                + Bytes.toString(row));
         }
         HRegionInfo regionInfo = Writables.getHRegionInfo(value);
         TRegionInfo region = new TRegionInfo();

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java?rev=1297322&r1=1297321&r2=1297322&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
Tue Mar  6 02:16:14 2012
@@ -116,6 +116,9 @@ public class TestThriftServer {
   public void doTestTableCreateDrop() throws Exception {
     ThriftServerRunner.HBaseHandler handler =
       new ThriftServerRunner.HBaseHandler(UTIL.getConfiguration());
+    doTestTableCreateDrop(handler);
+  }
+  public static void doTestTableCreateDrop(Hbase.Iface handler) throws Exception {
     createTestTables(handler);
     dropTestTables(handler);
   }
@@ -420,6 +423,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/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java?rev=1297322&r1=1297321&r2=1297322&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerCmdLine.java
Tue Mar  6 02:16:14 2012
@@ -194,22 +194,19 @@ public class TestThriftServerCmdLine {
     }
 
     sock.open();
-    TProtocol prot;
-    if (specifyCompact) {
-      prot = new TCompactProtocol(transport);
-    } else {
-      prot = new TBinaryProtocol(transport);
+    try {
+      TProtocol prot;
+      if (specifyCompact) {
+        prot = new TCompactProtocol(transport);
+      } else {
+        prot = new TBinaryProtocol(transport);
+      }
+      Hbase.Client client = new Hbase.Client(prot);
+      TestThriftServer.doTestTableCreateDrop(client);
+      TestThriftServer.doTestGetTableRegions(client);
+    } finally {
+      sock.close();
     }
-    Hbase.Client client = new Hbase.Client(prot);
-    List<ByteBuffer> tableNames = client.getTableNames();
-    if (tableNames.isEmpty()) {
-      TestThriftServer.createTestTables(client);
-      assertEquals(2, client.getTableNames().size());
-    } else {
-      assertEquals(2, tableNames.size());
-      assertEquals(2, client.getColumnDescriptors(tableNames.get(0)).size());
-    }
-    sock.close();
   }
 
   private void stopCmdLineThread() throws Exception {



Mime
View raw message