hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r665994 - in /hadoop/hbase/trunk: ./ src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/hbase/client/ src/test/org/apache/hadoop/hbase/regionserver/
Date Tue, 10 Jun 2008 07:46:15 GMT
Author: stack
Date: Tue Jun 10 00:46:14 2008
New Revision: 665994

URL: http://svn.apache.org/viewvc?rev=665994&view=rev
Log:
HBASE-662 UI in table.jsp gives META locations, not the table's regions location

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/MetaScanner.java
    hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=665994&r1=665993&r2=665994&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Jun 10 00:46:14 2008
@@ -44,6 +44,8 @@
    HBASE-670   Historian deadlocks if regionserver is at global memory boundary
                and is hosting .META.
    HBASE-665   Server side scanner doesn't honor stop row
+   HBASE-662   UI in table.jsp gives META locations, not the table's regions
+               location (Jean-Daniel Cryans via Stack)
    
   IMPROVEMENTS
    HBASE-559   MR example job to count table rows

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java?rev=665994&r1=665993&r2=665994&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HRegionInfo.java Tue Jun 10 00:46:14
2008
@@ -22,6 +22,8 @@
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.JenkinsHash;
@@ -53,12 +55,22 @@
     new HRegionInfo(1L, HTableDescriptor.META_TABLEDESC);
 
   /**
-   * Extracts table name prefix from a region name.
-   * Presumes region names are ASCII characters only.
-   * @param regionName A region name.
+   * Extracts table name prefix from a metaregion row name.
+   * @param regionName A metaregion row name.
    * @return The table prefix of a region name.
    */
   public static byte [] getTableNameFromRegionName(final byte [] regionName) {
+    return parseMetaRegionRow(regionName).get(0);
+  }
+
+  /**
+   * Parses passed metaregion row into its constituent parts.
+   * Presumes region names are ASCII characters only.
+   * @param regionName A metaregion row name.
+   * @return A list where first element is the tablename, second the row
+   * portion, and the third the id.
+   */
+  public static List<byte []> parseMetaRegionRow(final byte [] regionName) {
     int offset = -1;
     for (int i = 0; i < regionName.length; i++) {
       if (regionName[i] == DELIMITER) {
@@ -72,7 +84,30 @@
     }
     byte [] tableName = new byte[offset];
     System.arraycopy(regionName, 0, tableName, 0, offset);
-    return tableName;
+    // Now move in from the tail till we hit DELIMITER to find the id
+    offset = -1;
+    for (int i = regionName.length - 1; i > tableName.length; i--) {
+      if (regionName[i] == DELIMITER) {
+        offset = i;
+        break;
+      }
+    }
+    if (offset == -1) {
+      throw new IllegalArgumentException(Bytes.toString(regionName) +
+          " does not have parseable tail");
+    }
+    byte [] row = new byte[offset - (tableName.length + 1)];
+    System.arraycopy(regionName, tableName.length + 1, row, 0,
+      offset - (tableName.length + 1));
+    byte [] id = new byte[regionName.length - (offset + 1)];
+    System.arraycopy(regionName, offset + 1, id, 0,
+      regionName.length - (offset + 1));
+    // Now make up an array to hold the three parse pieces.
+    List<byte []> result = new ArrayList<byte []>(3);
+    result.add(tableName);
+    result.add(row);
+    result.add(id);
+    return result;
   }
 
   private byte [] endKey = HConstants.EMPTY_BYTE_ARRAY;

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=665994&r1=665993&r2=665994&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java Tue
Jun 10 00:46:14 2008
@@ -269,7 +269,7 @@
         /** {@inheritDoc} */
         public boolean processRow(
             @SuppressWarnings("unused") RowResult rowResult,
-            @SuppressWarnings("unused") HRegionLocation metaLocation,
+            @SuppressWarnings("unused") HRegionLocation regionLocation,
             HRegionInfo info) {
 
           // Only examine the rows where the startKey is zero length

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java?rev=665994&r1=665993&r2=665994&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java Tue Jun 10 00:46:14
2008
@@ -359,7 +359,7 @@
     MetaScannerVisitor visitor = new MetaScannerVisitor() {
       @SuppressWarnings("unused")
       public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
-          @SuppressWarnings("unused") HRegionLocation metaLocation,
+          @SuppressWarnings("unused") HRegionLocation regionLocation,
           HRegionInfo info)
       throws IOException {
         if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
@@ -388,14 +388,14 @@
 
     MetaScannerVisitor visitor = new MetaScannerVisitor() {
       public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
-          HRegionLocation metaLocation, HRegionInfo hri) {
+          HRegionLocation regionLocation, HRegionInfo hri) {
         
         HRegionInfo info = new UnmodifyableHRegionInfo(hri); 
         if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
           return false;
         }
         if (!(info.isOffline() || info.isSplit())) {
-          regionMap.put(info, metaLocation.getServerAddress());
+          regionMap.put(info, regionLocation.getServerAddress());
         }
         return true;
       }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/MetaScanner.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/MetaScanner.java?rev=665994&r1=665993&r2=665994&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/MetaScanner.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/MetaScanner.java Tue Jun 10
00:46:14 2008
@@ -1,6 +1,7 @@
 package org.apache.hadoop.hbase.client;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HConstants;
@@ -44,12 +45,11 @@
       MetaScannerVisitor visitor, byte[] tableName)
   throws IOException {
     HConnection connection = HConnectionManager.getConnection(configuration);
-    HRegionLocation metaLocation = null;
     boolean toContinue = true;
     byte [] startRow = Bytes.equals(tableName, EMPTY_START_ROW)? tableName:
       HRegionInfo.createRegionName(tableName, null, NINES);
       
-    // Scan over the each meta region
+    // Scan over each meta region
     do {
       ScannerCallable callable = new ScannerCallable(connection,
         META_TABLE_NAME, COL_REGIONINFO_ARRAY, tableName, LATEST_TIMESTAMP,
@@ -57,15 +57,17 @@
       try {
         // Open scanner
         connection.getRegionServerWithRetries(callable);
-        metaLocation = connection.locateRegion(META_TABLE_NAME, startRow);
         while (toContinue) {
           RowResult rowResult = connection.getRegionServerWithRetries(callable);
           if (rowResult == null || rowResult.size() == 0) {
             break;
           }
-          HRegionInfo info = Writables.
-            getHRegionInfo(rowResult.get(COL_REGIONINFO));
-          toContinue = visitor.processRow(rowResult, metaLocation, info);
+          HRegionInfo info = Writables.getHRegionInfo(rowResult
+              .get(COL_REGIONINFO));
+          List<byte []> parse = HRegionInfo.parseMetaRegionRow(info.getRegionName());
+          HRegionLocation regionLocation =
+            connection.locateRegion(parse.get(0), parse.get(1));
+          toContinue = visitor.processRow(rowResult, regionLocation, info);
         }
         // Advance the startRow to the end key of the current region
         startRow = callable.getHRegionInfo().getEndKey();
@@ -88,12 +90,12 @@
      * unnecessary for some reason.
      * 
      * @param rowResult
-     * @param metaLocation
+     * @param regionLocation
      * @param info
      * @return A boolean to know if it should continue to loop in the region
      * @throws IOException
      */
     public boolean processRow(RowResult rowResult,
-        HRegionLocation metaLocation, HRegionInfo info) throws IOException;
+        HRegionLocation regionLocation, HRegionInfo info) throws IOException;
   }
 }

Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java?rev=665994&r1=665993&r2=665994&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java
(original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java
Tue Jun 10 00:46:14 2008
@@ -19,11 +19,25 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
+import java.util.List;
+
 import org.apache.hadoop.hbase.HBaseTestCase;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.util.Bytes;
 
 public class TestHRegionInfo extends HBaseTestCase {
+  public void testParse() throws Exception {
+    String tableName = getName();
+    String row = getName();
+    long id = 12345;
+    List<byte []> parse =
+      HRegionInfo.parseMetaRegionRow(Bytes.toBytes(tableName + "," + row +
+        "," + Long.toString(id)));
+    assertEquals(Bytes.toString(parse.get(0)), tableName);
+    assertEquals(Bytes.toString(parse.get(1)), row);
+    assertEquals(Long.parseLong(Bytes.toString(parse.get(2))), id);
+  }
+  
   public void testCreateHRegionInfoName() throws Exception {
     String tableName = "tablename";
     final byte [] tn = Bytes.toBytes(tableName);



Mime
View raw message