diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java index 8dac05a31d3..56ae349843e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java @@ -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) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormatBase.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormatBase.java index ff413144050..6560b41d72d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormatBase.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormatBase.java @@ -96,6 +96,8 @@ extends InputFormat { * * @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 { throw new IOException("No table was provided."); } - RegionSizeCalculator sizeCalculator = new RegionSizeCalculator((HTable) table); - + RegionSizeCalculator sizeCalculator = new RegionSizeCalculator(regionLocator, admin); + Pair keys = getStartEndKeys(); if (keys == null || keys.getFirst() == null || keys.getFirst().length == 0) { @@ -287,25 +289,27 @@ extends InputFormat { * 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(); } /**