HBASE-12247 Replace setHTable() with initializeTable() in TableInputFormat. (Solomon Duskis)

This commit is contained in:
stack 2014-10-14 14:11:21 -07:00
parent dc86001523
commit 3544f4e98b
2 changed files with 11 additions and 10 deletions

View File

@ -30,7 +30,6 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
@ -109,9 +108,8 @@ implements Configurable {
this.conf = configuration;
TableName tableName = TableName.valueOf(conf.get(INPUT_TABLE));
try {
// TODO: Replace setHTable() with initializeTable() once we have
// a clean method of closing a connection.
setHTable(new HTable(new Configuration(conf), tableName));
// NOTE: This connection doesn't currently get closed explicit1ly.
initializeTable(ConnectionFactory.createConnection(new Configuration(conf)), tableName);
} catch (Exception e) {
LOG.error(StringUtils.stringifyException(e));
}
@ -183,7 +181,6 @@ implements Configurable {
*
* @param scan The Scan to update.
* @param familyAndQualifier family and qualifier
* @return A reference to this instance.
* @throws IllegalArgumentException When familyAndQualifier is invalid.
*/
private static void addColumn(Scan scan, byte[] familyAndQualifier) {

View File

@ -96,6 +96,8 @@ extends InputFormat<ImmutableBytesWritable, Result> {
*
* @see Scan */
private Scan scan = null;
/** The {@link Admin}. */
private Admin admin;
/** The {@link Table} to scan. */
private Table table;
/** The {@link RegionLocator} of the table. */
@ -163,8 +165,8 @@ extends InputFormat<ImmutableBytesWritable, Result> {
throw new IOException("No table was provided.");
}
RegionSizeCalculator sizeCalculator = new RegionSizeCalculator((HTable) table);
RegionSizeCalculator sizeCalculator = new RegionSizeCalculator(regionLocator, admin);
Pair<byte[][], byte[][]> keys = getStartEndKeys();
if (keys == null || keys.getFirst() == null ||
keys.getFirst().length == 0) {
@ -287,25 +289,27 @@ extends InputFormat<ImmutableBytesWritable, Result> {
* Allows subclasses to set the {@link HTable}.
*
* @param table The table to get the data from.
* @throws IOExceptfion
* @throws IOException
* @deprecated Use {@link #initializeTable(Connection, TableName)} instead.
*/
@Deprecated
protected void setHTable(HTable table) throws IOException {
this.table = table;
this.regionLocator = table;
this.admin = table.getConnection().getAdmin();
}
/**
* Allows subclasses to initalize the table information.
* Allows subclasses to initialize the table information.
*
* @param connection The {@link Connection} to the HBase cluster.
* @param tableName The {@link TableName} of the table to process.
* @throws IOExceptfion
* @throws IOException
*/
protected void initializeTable(Connection connection, TableName tableName) throws IOException {
this.table = connection.getTable(tableName);
this.regionLocator = connection.getRegionLocator(tableName);
this.admin = connection.getAdmin();
}
/**