Index: src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java (revision 1062080) +++ src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditor.java (working copy) @@ -130,4 +130,6 @@ pair.getFirst().getEncodedName()); LOG.info("Finished " + name); } + + TODO: VERIFY THAT METAREADER getMETAHTABLE USES SAME CONNECTION AS CT } \ No newline at end of file Index: src/main/java/org/apache/hadoop/hbase/HRegionLocation.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HRegionLocation.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/HRegionLocation.java (working copy) @@ -44,7 +44,7 @@ */ @Override public String toString() { - return "address: " + this.serverAddress.toString() + ", regioninfo: " + + return "address=" + this.serverAddress.toString() + ", regioninfo=" + this.regionInfo.getRegionNameAsString(); } Index: src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java (working copy) @@ -36,7 +36,9 @@ import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException; import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.ipc.HRegionInterface; import org.apache.hadoop.hbase.util.Bytes; @@ -252,24 +254,31 @@ public static void fullScan(CatalogTracker catalogTracker, final Visitor visitor, final byte [] startrow) throws IOException { - HRegionInterface metaServer = - catalogTracker.waitForMetaServerConnectionDefault(); Scan scan = new Scan(); if (startrow != null) scan.setStartRow(startrow); scan.addFamily(HConstants.CATALOG_FAMILY); - long scannerid = metaServer.openScanner( - HRegionInfo.FIRST_META_REGIONINFO.getRegionName(), scan); + HTable metaTable = getMetaHTable(catalogTracker); + ResultScanner scanner = metaTable.getScanner(scan); try { Result data; - while((data = metaServer.next(scannerid)) != null) { + while((data = scanner.next()) != null) { if (!data.isEmpty()) visitor.visit(data); } } finally { - metaServer.close(scannerid); + scanner.close(); + metaTable.close(); } return; } + static HTable getMetaHTable(final CatalogTracker ct) + throws IOException { + // Passing the CatalogTracker's connection configuration ensures this + // HTable instance uses the CatalogTracker's connection. + return new HTable(ct.getConnection().getConfiguration(), + HConstants.META_TABLE_NAME); + } + /** * Reads the location of META from ROOT. * @param metaServer connection to server hosting ROOT @@ -356,11 +365,14 @@ throws IOException { Get get = new Get(regionName); get.addFamily(HConstants.CATALOG_FAMILY); - byte [] meta = getCatalogRegionNameForRegion(regionName); - Result r = catalogTracker.waitForMetaServerConnectionDefault().get(meta, get); - if(r == null || r.isEmpty()) { - return null; + HTable metaTable = getMetaHTable(catalogTracker); + Result r = null; + try { + r = metaTable.get(get); + } finally { + metaTable.close(); } + if (r == null || r.isEmpty()) return null; return metaRowToRegionPair(r); } Index: src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -989,14 +989,14 @@ List exceptions = new ArrayList(); for(int tries = 0; tries < numRetries; tries++) { try { - callable.instantiateServer(tries != 0); + callable.connect(tries != 0); return callable.call(); } catch (Throwable t) { t = translateException(t); exceptions.add(t); if (tries == numRetries - 1) { - throw new RetriesExhaustedException(callable.getServerName(), - callable.getRegionName(), callable.getRow(), tries, exceptions); + throw new RetriesExhaustedException(callable.toString(), tries, + exceptions); } } try { @@ -1012,7 +1012,7 @@ public T getRegionServerWithoutRetries(ServerCallable callable) throws IOException, RuntimeException { try { - callable.instantiateServer(false); + callable.connect(false); return callable.call(); } catch (Throwable t) { Throwable t2 = translateException(t); @@ -1059,7 +1059,7 @@ return server.multi(multi); } @Override - public void instantiateServer(boolean reload) throws IOException { + public void connect(boolean reload) throws IOException { server = connection.getHRegionConnection(address); } } Index: src/main/java/org/apache/hadoop/hbase/client/RetriesExhaustedException.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/RetriesExhaustedException.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/client/RetriesExhaustedException.java (working copy) @@ -15,8 +15,6 @@ */ package org.apache.hadoop.hbase.client; -import org.apache.hadoop.hbase.util.Bytes; - import java.io.IOException; import java.util.List; @@ -37,27 +35,21 @@ /** * Create a new RetriesExhaustedException from the list of prior failures. - * @param serverName name of HRegionServer - * @param regionName name of region - * @param row The row we were pursuing when we ran out of retries + * @param callableVitals Details from the {@link ServerCallable} we were using + * when we got this exception. * @param numTries The number of tries we made * @param exceptions List of exceptions that failed before giving up */ - public RetriesExhaustedException(String serverName, final byte [] regionName, - final byte [] row, int numTries, List exceptions) { - super(getMessage(serverName, regionName, row, numTries, exceptions)); + public RetriesExhaustedException(final String callableVitals, int numTries, + List exceptions) { + super(getMessage(callableVitals, numTries, exceptions)); } - private static String getMessage(String serverName, final byte [] regionName, - final byte [] row, - int numTries, List exceptions) { - StringBuilder buffer = new StringBuilder("Trying to contact region server "); - buffer.append(serverName); - buffer.append(" for region "); - buffer.append(regionName == null? "": Bytes.toStringBinary(regionName)); - buffer.append(", row '"); - buffer.append(row == null? "": Bytes.toStringBinary(row)); - buffer.append("', but failed after "); + private static String getMessage(String callableVitals, int numTries, + List exceptions) { + StringBuilder buffer = new StringBuilder("Failed contacting "); + buffer.append(callableVitals); + buffer.append(" after "); buffer.append(numTries + 1); buffer.append(" attempts.\nExceptions:\n"); for (Throwable t : exceptions) { Index: src/main/java/org/apache/hadoop/hbase/client/HTable.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HTable.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/client/HTable.java (working copy) @@ -170,7 +170,8 @@ } this.connection = HConnectionManager.getConnection(conf); this.scannerTimeout = - (int) conf.getLong(HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, HConstants.DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD); + (int)conf.getLong(HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, + HConstants.DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD); this.configuration = conf; this.connection.locateRegion(tableName, HConstants.EMPTY_START_ROW); this.writeBufferSize = conf.getLong("hbase.client.write.buffer", 2097152); Index: src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java (working copy) @@ -58,9 +58,9 @@ * @throws IOException */ @Override - public void instantiateServer(boolean reload) throws IOException { + public void connect(boolean reload) throws IOException { if (!instantiated || reload) { - super.instantiateServer(reload); + super.connect(reload); instantiated = true; } } Index: src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java (revision 1062080) +++ src/main/java/org/apache/hadoop/hbase/client/ServerCallable.java (working copy) @@ -22,12 +22,21 @@ import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.ipc.HRegionInterface; +import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException; import java.util.concurrent.Callable; /** - * Abstract class that implements Callable, used by retryable actions. + * Abstract class that implements {@link Callable}. Implementation stipulates + * return type and method we actually invoke on remote Server. Usually + * used inside a try/catch that fields usual connection failures all wrapped + * up in a retry loop. + *

Call {@link #connect(boolean)} to connect to server hosting region + * that contains the passed row in the passed table before invoking + * {@link #call()}. + * @see HConnection#getRegionServerWithoutRetries(ServerCallable) + * * @param the class that the ServerCallable handles */ public abstract class ServerCallable implements Callable { @@ -38,9 +47,9 @@ protected HRegionInterface server; /** - * @param connection connection callable is on - * @param tableName table name callable is on - * @param row row we are querying + * @param connection Connection to use. + * @param tableName Table name to which row belongs. + * @param row The row we want in tableName. */ public ServerCallable(HConnection connection, byte [] tableName, byte [] row) { this.connection = connection; @@ -49,33 +58,21 @@ } /** - * - * @param reload set this to true if connection should re-find the region + * Connect to the server hosting region with row from tablename. + * @param reload Set this to true if connection should re-find the region * @throws IOException e */ - public void instantiateServer(boolean reload) throws IOException { + public void connect(final boolean reload) throws IOException { this.location = connection.getRegionLocation(tableName, row, reload); this.server = connection.getHRegionConnection(location.getServerAddress()); } - /** @return the server name */ - public String getServerName() { - if (location == null) { - return null; - } - return location.getServerAddress().toString(); + /** + * @return String of current state. + */ + public String toString() { + return (location == null? "null": location.toString()) + + ", tableName=" + (tableName == null? "": Bytes.toString(this.tableName)) + + ", row=" + (row == null? "": Bytes.toStringBinary(this.row)); } - - /** @return the region name */ - public byte[] getRegionName() { - if (location == null) { - return null; - } - return location.getRegionInfo().getRegionName(); - } - - /** @return the row */ - public byte [] getRow() { - return row; - } } \ No newline at end of file