diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index dd118751167..ede1e97bdbc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -412,6 +412,15 @@ public class HRegionInfo implements Comparable { return tableName; } + /** + * Gets the start key from the specified region name. + * @param regionName + * @return Start key. + */ + public static byte[] getStartKey(final byte[] regionName) throws IOException { + return parseRegionName(regionName)[1]; + } + /** * Separate elements of a regionName. * @param regionName diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnection.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnection.java index 9456b9c93e3..64f434b89e0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnection.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnection.java @@ -176,8 +176,20 @@ public interface HConnection extends Abortable, Closeable { * @return list of region locations for all regions of table * @throws IOException */ - public List locateRegions(byte[] tableName) + public List locateRegions(final byte[] tableName) throws IOException; + + /** + * Gets the locations of all regions in the specified table, tableName. + * @param tableName table to get regions of + * @param useCache Should we use the cache to retrieve the region information. + * @param offlined True if we are to include offlined regions, false and we'll leave out offlined + * regions from returned list. + * @return list of region locations for all regions of table + * @throws IOException + */ + public List locateRegions(final byte[] tableName, final boolean useCache, + final boolean offlined) throws IOException; /** * Returns a {@link MasterAdminProtocol} to the active master diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index e8942a8fb90..793bb6996f1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -35,6 +35,7 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.NavigableMap; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Callable; @@ -893,17 +894,27 @@ public class HConnectionManager { } @Override - public HRegionLocation locateRegion(final byte [] regionName) - throws IOException { - // TODO implement. use old stuff or new stuff? - return null; + public HRegionLocation locateRegion(final byte[] regionName) throws IOException { + return locateRegion(HRegionInfo.getTableName(regionName), + HRegionInfo.getStartKey(regionName), false, true); } @Override - public List locateRegions(final byte [] tableName) + public List locateRegions(final byte[] tableName) throws IOException { - // TODO implement. use old stuff or new stuff? - return null; + return locateRegions (tableName, false, true); + } + + @Override + public List locateRegions(final byte[] tableName, final boolean useCache, + final boolean offlined) throws IOException { + NavigableMap regions = MetaScanner.allTableRegions(conf, tableName, + offlined); + final List locations = new ArrayList(); + for (HRegionInfo regionInfo : regions.keySet()) { + locations.add(locateRegion(tableName, regionInfo.getStartKey(), useCache, true)); + } + return locations; } @Override