Review Board 1.7.22


HBASE-5489: Add HTable accessor to get regions for a key range

Review Request #4117 - Created March 1, 2012 and updated

David Wang
trunk
HBASE-5489
Reviewers
hbase
hbase-git
getRegionsInRange() will retrieve the HRegionLocations for the regions associated with the specified key range, using client-side cache if possible.

I have one question: right now the endKey specified to getRegionsInRange() is treated as inclusive.  I followed the behavior that I saw in HRegionInfo.containsRange().  However, other HBase code such as Scan treats the endKey as exclusive.  So I am not clear as to which way we should go here.  I can easily change the patch if we want the endKey to be exclusive; please let me know.  Thanks in advance.
Ran the TestFromClientSide unit tests and passed repeatedly.

Ran test-patch.sh with the following results:

-1 overall.  

    +1 @author.  The patch does not contain any @author tags.

    +1 tests included.  The patch appears to include 3 new or modified tests.

    -1 javadoc.  The javadoc tool appears to have generated -129 warning messages.

    +1 javac.  The applied patch does not increase the total number of javac compiler warnings.

    +1 findbugs.  The patch does not introduce any new Findbugs (version ) warnings.

    +1 release audit.  The applied patch does not increase the total number of release audit warnings.

Diff revision 2

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

1 2 3
1 2 3

  1. src/main/java/org/apache/hadoop/hbase/client/HTable.java: Loading...
  2. src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java: Loading...
src/main/java/org/apache/hadoop/hbase/client/HTable.java
Revision 29b8004 New Change
[20] 485 lines
[+20] [+] public boolean processRow(Result rowResult) throws IOException {
486
  public NavigableMap<HRegionInfo, ServerName> getRegionLocations() throws IOException {
486
  public NavigableMap<HRegionInfo, ServerName> getRegionLocations() throws IOException {
487
    return MetaScanner.allTableRegions(getConfiguration(), getTableName(), false);
487
    return MetaScanner.allTableRegions(getConfiguration(), getTableName(), false);
488
  }
488
  }
489

    
   
489

   
490
  /**
490
  /**

    
   
491
   * Get the corresponding regions for an arbitrary range of keys.

    
   
492
   * <p>

    
   
493
   * @param startRow Starting row in range, inclusive

    
   
494
   * @param endRow Ending row in range, inclusive

    
   
495
   * @return A list of HRegionLocations corresponding to the regions that

    
   
496
   * contain the specified range

    
   
497
   * @throws IOException if a remote or network exception occurs

    
   
498
   */

    
   
499
  public List<HRegionLocation> getRegionsInRange(final byte [] startKey,

    
   
500
    final byte [] endKey) throws IOException {

    
   
501
    final boolean endKeyIsEndOfTable = Bytes.equals(endKey,

    
   
502
                                                    HConstants.EMPTY_END_ROW);

    
   
503
    if ((Bytes.compareTo(startKey, endKey) > 0) &&

    
   
504
        (endKeyIsEndOfTable == false)) {

    
   
505
      throw new IllegalArgumentException(

    
   
506
        "Invalid range: " + Bytes.toStringBinary(startKey) +

    
   
507
        " > " + Bytes.toStringBinary(endKey));

    
   
508
    }

    
   
509
    final List<HRegionLocation> regionList = new ArrayList<HRegionLocation>();

    
   
510
    byte [] currentKey = startKey;

    
   
511
    do {

    
   
512
      HRegionLocation regionLocation = getRegionLocation(currentKey, false);

    
   
513
      regionList.add(regionLocation);

    
   
514
      currentKey = regionLocation.getRegionInfo().getEndKey();

    
   
515
    } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW) &&

    
   
516
             (endKeyIsEndOfTable == true ||

    
   
517
              Bytes.compareTo(currentKey, endKey) < 0));

    
   
518
    return regionList;

    
   
519
  }

    
   
520

   

    
   
521
  /**
491
   * Save the passed region information and the table's regions
522
   * Save the passed region information and the table's regions
492
   * cache.
523
   * cache.
493
   * <p>
524
   * <p>
494
   * This is mainly useful for the MapReduce integration. You can call
525
   * This is mainly useful for the MapReduce integration. You can call
495
   * {@link #deserializeRegionInfo deserializeRegionInfo}
526
   * {@link #deserializeRegionInfo deserializeRegionInfo}
[+20] [20] 784 lines
src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Revision bdeaefe New Change
 
  1. src/main/java/org/apache/hadoop/hbase/client/HTable.java: Loading...
  2. src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java: Loading...