hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1130316 - in /hbase/trunk: ./ src/main/java/org/apache/hadoop/hbase/client/ src/main/java/org/apache/hadoop/hbase/thrift/ src/test/java/org/apache/hadoop/hbase/client/ src/test/java/org/apache/hadoop/hbase/thrift/
Date Wed, 01 Jun 2011 21:51:03 GMT
Author: stack
Date: Wed Jun  1 21:51:02 2011
New Revision: 1130316

URL: http://svn.apache.org/viewvc?rev=1130316&view=rev
Log:
HBASE-2556 Add convenience method to HBaseAdmin to get a collection of HRegionInfo objects
for each table

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1130316&r1=1130315&r2=1130316&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Wed Jun  1 21:51:02 2011
@@ -236,6 +236,8 @@ Release 0.91.0 - Unreleased
    HBASE-3931  Allow adding attributes to Get
    HBASE-3942  The thrift scannerOpen functions should support row caching
                (Adam Worthington)
+   HBASE-2556  Add convenience method to HBaseAdmin to get a collection of
+               HRegionInfo objects for each table (Ming Ma)
 
   TASKS
    HBASE-3559  Move report of split to master OFF the heartbeat channel

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1130316&r1=1130315&r2=1130316&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Wed Jun  1 21:51:02
2011
@@ -21,8 +21,10 @@ package org.apache.hadoop.hbase.client;
 
 import java.io.Closeable;
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -1240,6 +1242,27 @@ public class HBaseAdmin implements Abort
     new HBaseAdmin(copyOfConf);
   }
 
+  /**
+   * get the regions of a given table.
+   *
+   * @param tableName the name of the table
+   * @return Ordered list of {@link HRegionInfo}.   * 
+   * @throws IOException
+   */  
+  public List<HRegionInfo> getTableRegions(final byte[] tableName) throws IOException
+  {
+      CatalogTracker ct = getCatalogTracker();
+      List<HRegionInfo> Regions;
+      try {
+          Regions = MetaReader.getTableRegions(ct, tableName, true);
+        } finally {
+          cleanupCatalogTracker(ct);
+        }
+      
+      return Regions;	  
+  }
+  
+  
   public void close() throws IOException {
     if (this.connection != null) {
       this.connection.close();

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java?rev=1130316&r1=1130315&r2=1130316&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java Wed Jun  1
21:51:02 2011
@@ -270,11 +270,10 @@ public class ThriftServer {
     public List<TRegionInfo> getTableRegions(ByteBuffer tableName)
     throws IOError {
       try{
-        HTable table = getTable(tableName);
-        Map<HRegionInfo, HServerAddress> regionsInfo = table.getRegionsInfo();
+        List<HRegionInfo> HRegions = this.admin.getTableRegions(tableName.array());
         List<TRegionInfo> regions = new ArrayList<TRegionInfo>();
 
-        for (HRegionInfo regionInfo : regionsInfo.keySet()){
+        for (HRegionInfo regionInfo : HRegions){
           TRegionInfo region = new TRegionInfo();
           region.startKey = ByteBuffer.wrap(regionInfo.getStartKey());
           region.endKey = ByteBuffer.wrap(regionInfo.getEndKey());

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1130316&r1=1130315&r2=1130316&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Wed Jun  1 21:51:02
2011
@@ -830,4 +830,35 @@ public class TestAdmin {
       this.admin.deleteTable(tableName);
     }
   }
-}
\ No newline at end of file
+  
+
+  /**
+   * For HBASE-2556
+   * @throws IOException
+   */  
+  @Test
+  public void testGetTableRegions() throws IOException {
+
+    byte[] tableName = Bytes.toBytes("testGetTableRegions");
+
+    int expectedRegions = 10;
+
+    // Use 80 bit numbers to make sure we aren't limited
+    byte [] startKey = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
+    byte [] endKey =   { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
+
+
+    HTableDescriptor desc = new HTableDescriptor(tableName);
+    desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
+    admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
+    admin.createTable(desc, startKey, endKey, expectedRegions);
+
+    List<HRegionInfo> RegionInfos = admin.getTableRegions(tableName);
+    
+    assertEquals("Tried to create " + expectedRegions + " regions " +
+        "but only found " + RegionInfos.size(),
+        expectedRegions, RegionInfos.size());
+    
+ }
+  
+}

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=1130316&r1=1130315&r2=1130316&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 Wed Jun
 1 21:51:02 2011
@@ -66,6 +66,7 @@ public class TestThriftServer extends HB
     doTestTableMutations();
     doTestTableTimestampsAndColumns();
     doTestTableScanners();
+    doTestGetTableRegions();
   }
 
   /**
@@ -98,7 +99,8 @@ public class TestThriftServer extends HB
     handler.disableTable(tableAname);*/
     handler.deleteTable(tableAname);
   }
-
+  
+    
   /**
    * Tests adding a series of Mutations and BatchMutations, including a
    * delete mutation.  Also tests data retrieval, and getting back multiple
@@ -310,6 +312,27 @@ public class TestThriftServer extends HB
     handler.deleteTable(tableAname);
   }
 
+  
+  /**
+   * For HBASE-2556
+   * Tests for GetTableRegions
+   *
+   * @throws Exception
+   */
+  public void doTestGetTableRegions() throws Exception {
+    ThriftServer.HBaseHandler handler = new ThriftServer.HBaseHandler(this.conf);
+
+    handler.createTable(tableAname, getColumnDescriptors());
+    int RegionCount = handler.getTableRegions(tableAname).size();
+    assertEquals("empty table should have only 1 region, " +
+            "but found " + RegionCount, RegionCount, 1);
+    handler.disableTable(tableAname);    
+    handler.deleteTable(tableAname);
+    RegionCount = handler.getTableRegions(tableAname).size();
+    assertEquals("non-existing table should have 0 region, " +
+            "but found " + RegionCount, RegionCount, 0);    
+  } 
+  
   /**
    *
    * @return a List of ColumnDescriptors for use in creating a table.  Has one



Mime
View raw message