qualifier as an HRegionInfo and return it, or null.
- * @param r Result instance to pull from.
- * @param qualifier Column family qualifier
- * @return An HRegionInfo instance or null.
- * @throws IOException
- */
- private static HRegionInfo getHRegionInfo(final Result r, byte [] qualifier)
- throws IOException {
- byte [] bytes = r.getValue(HConstants.CATALOG_FAMILY, qualifier);
- if (bytes == null || bytes.length <= 0) return null;
- return Writables.getHRegionInfoOrNull(bytes);
- }
-
- /**
* Look for presence of the daughter OR of a split of the daughter. Daughter
* could have been split over on regionserver before a run of the
* catalogJanitor had chance to clear reference from parent.
@@ -278,7 +262,7 @@
@Override
public boolean visit(Result r) throws IOException {
- HRegionInfo hri = getHRegionInfo(r, HConstants.REGIONINFO_QUALIFIER);
+ HRegionInfo hri = MetaReader.getHRegionInfo(r, HConstants.REGIONINFO_QUALIFIER);
if (hri == null) {
LOG.warn("No serialized HRegionInfo in " + r);
return true;
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)
@@ -28,6 +28,8 @@
import java.util.TreeMap;
import java.util.TreeSet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HServerAddress;
@@ -36,7 +38,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;
@@ -51,6 +55,7 @@
* catalogs.
*/
public class MetaReader {
+ private static final Log LOG = LogFactory.getLog(MetaReader.class);
public static final byte [] META_REGION_PREFIX;
static {
// Copy the prefix from FIRST_META_REGIONINFO into META_REGION_PREFIX.
@@ -92,19 +97,6 @@
/**
* @param regionName
- * @return Returns region name to look in for regionName;
- * e.g. if we are looking for .META.,,1 region, we need to look
- * in -ROOT- region, else if a user region, we need to look
- * in the .META.,,1 region.
- */
- private static byte [] getCatalogRegionNameForRegion(final byte [] regionName) {
- return isMetaRegion(regionName)?
- HRegionInfo.ROOT_REGIONINFO.getRegionName():
- HRegionInfo.FIRST_META_REGIONINFO.getRegionName();
- }
-
- /**
- * @param regionName
* @return True if regionName is from .META. table.
*/
private static boolean isMetaRegion(final byte [] regionName) {
@@ -208,20 +200,40 @@
public static List.META..
*
* Returns a map of every region to it's currently assigned server, according
@@ -252,24 +264,33 @@
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) {
- if (!data.isEmpty()) visitor.visit(data);
+ while((data = scanner.next()) != null) {
+ if (data.isEmpty()) continue;
+ // Break if visit returns false.
+ if (!visitor.visit(data)) break;
}
} 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 +377,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);
}
@@ -476,7 +500,7 @@
* @throws IOException
*/
public static List 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 .META. when passed a
+ * tableName; returns <tableName&rt; <,&rt; <,&rt;
+ */
+ static byte [] getTableStartRowForMeta(final byte [] tableName) {
+ byte [] startRow = new byte[tableName.length + 2];
+ System.arraycopy(tableName, 0, startRow, 0, tableName.length);
+ startRow[startRow.length - 2] = HRegionInfo.DELIMITER;
+ startRow[startRow.length - 1] = HRegionInfo.DELIMITER;
+ return startRow;
+ }
+
+ /**
* @param catalogTracker
* @param tableName
* @return Return list of regioninfos and server addresses.
@@ -607,6 +647,23 @@
}
/**
+ * Interpret the content of the cell at {@link HConstants#CATALOG_FAMILY} and
+ * qualifier as an HRegionInfo and return it, or null.
+ * @param r Result instance to pull from.
+ * @param qualifier Column family qualifier -- either
+ * {@link HConstants#SPLITA_QUALIFIER}, {@link HConstants#SPLITB_QUALIFIER} or
+ * {@link HConstants#REGIONINFO_QUALIFIER}.
+ * @return An HRegionInfo instance or null.
+ * @throws IOException
+ */
+ public static HRegionInfo getHRegionInfo(final Result r, byte [] qualifier)
+ throws IOException {
+ byte [] bytes = r.getValue(HConstants.CATALOG_FAMILY, qualifier);
+ if (bytes == null || bytes.length <= 0) return null;
+ return Writables.getHRegionInfoOrNull(bytes);
+ }
+
+ /**
* Implementations 'visit' a catalog table row.
*/
public interface Visitor {
@@ -618,4 +675,4 @@
*/
public boolean visit(final Result r) throws IOException;
}
-}
+}
\ No newline at end of file
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 @@
Listrow 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