diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java index c57064b..2e1bd64 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java @@ -112,6 +112,11 @@ class ConnectionAdapter implements ClusterConnection { } @Override + public RegionLocator getRegionLocation(TableName tableName) throws IOException { + return wrappedConnection.getRegionLocation(tableName); + } + + @Override public Admin getAdmin() throws IOException { return wrappedConnection.getAdmin(); } diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java index ad18e23..706b3e4 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java @@ -714,6 +714,14 @@ class ConnectionManager { } @Override + public RegionLocator getRegionLocation(TableName tableName) throws IOException { + if (managed) { + throw new IOException("The connection has to be unmanaged."); + } + return new HTable(tableName, this, getBatchPool()); + } + + @Override public Admin getAdmin() throws IOException { if (managed) { throw new IOException("The connection has to be unmanaged."); diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java index 77e9a5e..321f649 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java @@ -154,11 +154,25 @@ public interface HConnection extends Abortable, Closeable { public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException; /** + * Retrieve a RegionLocator implementation to inspect region information on a table. The returned + * RegionLocator is not thread-safe, so a new instance should be created for each using thread. + * + * This is a lightweight operation. Pooling or caching of teh returned RegionLocator is neither + * required nor desired. + * + * RegionLocator needs to be unmanaged + * (created with {@link HConnectionManager#createConnection(Configuration)}). + * + * @param tableName Name of the table who's region is to be examined + * @return A RegionLocator instance + */ + public RegionLocator getRegionLocation(TableName tableName) throws IOException; + + /** * Retrieve an Admin implementation to administer an HBase cluster. * The returned Admin is not guaranteed to be thread-safe. A new instance should be created for * each using thread. This is a lightweight operation. Pooling or caching of the returned * Admin is not recommended. Note that HConnection needs to be unmanaged - * (created with {@link HConnectionManager#createConnection(Configuration)}). * * @return an Admin instance for cluster administration */ diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index 1265a5f..ad53480 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -123,7 +123,7 @@ import com.google.protobuf.ServiceException; */ @InterfaceAudience.Public @InterfaceStability.Stable -public class HTable implements HTableInterface { +public class HTable implements HTableInterface, RegionLocator { private static final Log LOG = LogFactory.getLog(HTable.class); protected ClusterConnection connection; private final TableName tableName; @@ -498,30 +498,27 @@ public class HTable implements HTableInterface { * @param row Row to find. * @return The location of the given row. * @throws IOException if a remote or network exception occurs + * @deprecated Use {@link RegionLocator#getRegionLocation(byte[])} */ + @Deprecated public HRegionLocation getRegionLocation(final String row) throws IOException { return connection.getRegionLocation(tableName, Bytes.toBytes(row), false); } /** - * Finds the region on which the given row is being served. Does not reload the cache. - * @param row Row to find. - * @return Location of the row. - * @throws IOException if a remote or network exception occurs + * {@inheritDoc} */ + @Override public HRegionLocation getRegionLocation(final byte [] row) throws IOException { return connection.getRegionLocation(tableName, row, false); } /** - * Finds the region on which the given row is being served. - * @param row Row to find. - * @param reload true to reload information or false to use cached information - * @return Location of the row. - * @throws IOException if a remote or network exception occurs + * {@inheritDoc} */ + @Override public HRegionLocation getRegionLocation(final byte [] row, boolean reload) throws IOException { return connection.getRegionLocation(tableName, row, reload); @@ -599,36 +596,25 @@ public class HTable implements HTableInterface { } /** - * Gets the starting row key for every region in the currently open table. - *
- * This is mainly useful for the MapReduce integration. - * @return Array of region starting row keys - * @throws IOException if a remote or network exception occurs + * {@inheritDoc} */ + @Override public byte [][] getStartKeys() throws IOException { return getStartEndKeys().getFirst(); } /** - * Gets the ending row key for every region in the currently open table. - *
- * This is mainly useful for the MapReduce integration. - * @return Array of region ending row keys - * @throws IOException if a remote or network exception occurs + * {@inheritDoc} */ + @Override public byte[][] getEndKeys() throws IOException { return getStartEndKeys().getSecond(); } /** - * Gets the starting and ending row keys for every region in the currently - * open table. - *
- * This is mainly useful for the MapReduce integration.
- * @return Pair of arrays of region starting and ending row keys
- * @throws IOException if a remote or network exception occurs
+ * {@inheritDoc}
*/
- // TODO: these are not in HTableInterface. Should we add them there or move these to HBaseAdmin?
+ @Override
public Pair
+ * This is mainly useful for the MapReduce integration.
+ * @return Array of region starting row keys
+ * @throws IOException if a remote or network exception occurs
+ */
+ public byte [][] getStartKeys() throws IOException;
+
+ /**
+ * Gets the ending row key for every region in the currently open table.
+ *
+ * This is mainly useful for the MapReduce integration.
+ * @return Array of region ending row keys
+ * @throws IOException if a remote or network exception occurs
+ */
+ public byte[][] getEndKeys() throws IOException;
+
+ /**
+ * Gets the starting and ending row keys for every region in the currently
+ * open table.
+ *
+ * This is mainly useful for the MapReduce integration.
+ * @return Pair of arrays of region starting and ending row keys
+ * @throws IOException if a remote or network exception occurs
+ */
+ public Pair