HBASE-14711 Remove or annotate deprecated methods in HRegionInfo

This commit is contained in:
Jonathan M Hsieh 2015-10-28 11:16:48 -07:00
parent 6cc6d833f2
commit 4c25549e9f
16 changed files with 55 additions and 171 deletions

View File

@ -31,7 +31,6 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
import org.apache.hadoop.hbase.KeyValue.KVComparator;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.master.RegionState;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
@ -41,8 +40,6 @@ import org.apache.hadoop.hbase.util.ByteStringer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JenkinsHash;
import org.apache.hadoop.hbase.util.MD5Hash;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.PairOfSameType;
import org.apache.hadoop.io.DataInputBuffer;
/**
@ -839,7 +836,7 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
/**
* @return Comparator to use comparing {@link KeyValue}s.
* @deprecated This method should not have been here. Use Region#getCellComparator()
* @deprecated Use Region#getCellComparator(). deprecated for hbase 2.0, remove for hbase 3.0
*/
@Deprecated
public KVComparator getComparator() {
@ -1095,119 +1092,6 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
}
}
/**
* Extract a HRegionInfo and ServerName from catalog table {@link Result}.
* @param r Result to pull from
* @return A pair of the {@link HRegionInfo} and the {@link ServerName}
* (or null for server address if no address set in hbase:meta).
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static Pair<HRegionInfo, ServerName> getHRegionInfoAndServerName(final Result r) {
HRegionInfo info =
getHRegionInfo(r, HConstants.REGIONINFO_QUALIFIER);
ServerName sn = getServerName(r);
return new Pair<HRegionInfo, ServerName>(info, sn);
}
/**
* Returns HRegionInfo object from the column
* HConstants.CATALOG_FAMILY:HConstants.REGIONINFO_QUALIFIER of the catalog
* table Result.
* @param data a Result object from the catalog table scan
* @return HRegionInfo or null
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static HRegionInfo getHRegionInfo(Result data) {
return getHRegionInfo(data, HConstants.REGIONINFO_QUALIFIER);
}
/**
* Returns the daughter regions by reading the corresponding columns of the catalog table
* Result.
* @param data a Result object from the catalog table scan
* @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split
* parent
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static PairOfSameType<HRegionInfo> getDaughterRegions(Result data) throws IOException {
HRegionInfo splitA = getHRegionInfo(data, HConstants.SPLITA_QUALIFIER);
HRegionInfo splitB = getHRegionInfo(data, HConstants.SPLITB_QUALIFIER);
return new PairOfSameType<HRegionInfo>(splitA, splitB);
}
/**
* Returns the merge regions by reading the corresponding columns of the catalog table
* Result.
* @param data a Result object from the catalog table scan
* @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split
* parent
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static PairOfSameType<HRegionInfo> getMergeRegions(Result data) throws IOException {
HRegionInfo mergeA = getHRegionInfo(data, HConstants.MERGEA_QUALIFIER);
HRegionInfo mergeB = getHRegionInfo(data, HConstants.MERGEB_QUALIFIER);
return new PairOfSameType<HRegionInfo>(mergeA, mergeB);
}
/**
* Returns the HRegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and
* <code>qualifier</code> of the catalog table result.
* @param r a Result object from the catalog table scan
* @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.
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static HRegionInfo getHRegionInfo(final Result r, byte [] qualifier) {
Cell cell = r.getColumnLatestCell(
HConstants.CATALOG_FAMILY, qualifier);
if (cell == null) return null;
return parseFromOrNull(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}
/**
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static ServerName getServerName(final Result r) {
Cell cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
if (cell == null || cell.getValueLength() == 0) return null;
String hostAndPort = Bytes.toString(
cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY,
HConstants.STARTCODE_QUALIFIER);
if (cell == null || cell.getValueLength() == 0) return null;
try {
return ServerName.valueOf(hostAndPort,
Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
} catch (IllegalArgumentException e) {
LOG.error("Ignoring invalid region for server " + hostAndPort + "; cell=" + cell, e);
return null;
}
}
/**
* The latest seqnum that the server writing to meta observed when opening the region.
* E.g. the seqNum when the result of {@link #getServerName(Result)} was written.
* @param r Result to pull the seqNum from
* @return SeqNum, or HConstants.NO_SEQNUM if there's no value written.
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static long getSeqNumDuringOpen(final Result r) {
Cell cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.SEQNUM_QUALIFIER);
if (cell == null || cell.getValueLength() == 0) return HConstants.NO_SEQNUM;
return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}
/**
* Parses an HRegionInfo instance from the passed in stream. Presumes the HRegionInfo was
* serialized to the stream with {@link #toDelimitedByteArray()}

View File

@ -302,7 +302,7 @@ public class MetaTableAccessor {
parsedInfo = parseRegionInfoFromRegionName(regionName);
row = getMetaKeyForRegion(parsedInfo);
} catch (Exception parseEx) {
// Ignore. This is used with tableName passed as regionName.
; // Ignore. This is used with tableName passed as regionName.
}
Get get = new Get(row);
get.addFamily(HConstants.CATALOG_FAMILY);
@ -919,7 +919,8 @@ public class MetaTableAccessor {
* @return A ServerName instance or null if necessary fields not found or empty.
*/
@Nullable
private static ServerName getServerName(final Result r, final int replicaId) {
@InterfaceAudience.Private // for use by HMaster#getTableRegionRow which is used for testing only
public static ServerName getServerName(final Result r, final int replicaId) {
byte[] serverColumn = getServerColumn(replicaId);
Cell cell = r.getColumnLatestCell(getCatalogFamily(), serverColumn);
if (cell == null || cell.getValueLength() == 0) return null;
@ -928,8 +929,13 @@ public class MetaTableAccessor {
byte[] startcodeColumn = getStartCodeColumn(replicaId);
cell = r.getColumnLatestCell(getCatalogFamily(), startcodeColumn);
if (cell == null || cell.getValueLength() == 0) return null;
return ServerName.valueOf(hostAndPort,
Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
try {
return ServerName.valueOf(hostAndPort,
Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
} catch (IllegalArgumentException e) {
LOG.error("Ignoring invalid region for server " + hostAndPort + "; cell=" + cell, e);
return null;
}
}
/**
@ -1237,19 +1243,6 @@ public class MetaTableAccessor {
}
}
/**
* Count regions in <code>hbase:meta</code> for passed table.
* @param c Configuration object
* @param tableName table name to count regions for
* @return Count or regions in table <code>tableName</code>
* @throws IOException
*/
@Deprecated
public static int getRegionCount(final Configuration c, final String tableName)
throws IOException {
return getRegionCount(c, TableName.valueOf(tableName));
}
/**
* Count regions in <code>hbase:meta</code> for passed table.
* @param c Configuration object

View File

@ -2091,6 +2091,7 @@ public class HBaseAdmin implements Admin {
compact(master, getMobRegionInfo(tableName), major, columnFamily);
break;
case NORMAL:
default:
ZooKeeperWatcher zookeeper = null;
try {
checkTableExists(tableName);
@ -2685,7 +2686,7 @@ public class HBaseAdmin implements Admin {
MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {
@Override
public boolean visit(Result data) throws IOException {
HRegionInfo info = HRegionInfo.getHRegionInfo(data);
HRegionInfo info = MetaTableAccessor.getHRegionInfo(data);
if (info == null) {
LOG.warn("No serialized HRegionInfo in " + data);
return true;
@ -4371,6 +4372,7 @@ public class HBaseAdmin implements Admin {
}
break;
case NORMAL:
default:
ZooKeeperWatcher zookeeper =
new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(),
new ThrowableAbortable());

View File

@ -113,8 +113,8 @@ public class CatalogJanitor extends ScheduledChore {
* parent regioninfos
* @throws IOException
*/
Triple<Integer, Map<HRegionInfo, Result>, Map<HRegionInfo, Result>> getMergedRegionsAndSplitParents()
throws IOException {
Triple<Integer, Map<HRegionInfo, Result>, Map<HRegionInfo, Result>>
getMergedRegionsAndSplitParents() throws IOException {
return getMergedRegionsAndSplitParents(null);
}
@ -128,8 +128,8 @@ public class CatalogJanitor extends ScheduledChore {
* parent regioninfos
* @throws IOException
*/
Triple<Integer, Map<HRegionInfo, Result>, Map<HRegionInfo, Result>> getMergedRegionsAndSplitParents(
final TableName tableName) throws IOException {
Triple<Integer, Map<HRegionInfo, Result>, Map<HRegionInfo, Result>>
getMergedRegionsAndSplitParents(final TableName tableName) throws IOException {
final boolean isTableSpecified = (tableName != null);
// TODO: Only works with single hbase:meta region currently. Fix.
final AtomicInteger count = new AtomicInteger(0);
@ -145,7 +145,7 @@ public class CatalogJanitor extends ScheduledChore {
public boolean visit(Result r) throws IOException {
if (r == null || r.isEmpty()) return true;
count.incrementAndGet();
HRegionInfo info = HRegionInfo.getHRegionInfo(r);
HRegionInfo info = MetaTableAccessor.getHRegionInfo(r);
if (info == null) return true; // Keep scanning
if (isTableSpecified
&& info.getTable().compareTo(tableName) > 0) {
@ -225,10 +225,9 @@ public class CatalogJanitor extends ScheduledChore {
int mergeCleaned = 0;
Map<HRegionInfo, Result> mergedRegions = scanTriple.getSecond();
for (Map.Entry<HRegionInfo, Result> e : mergedRegions.entrySet()) {
HRegionInfo regionA = HRegionInfo.getHRegionInfo(e.getValue(),
HConstants.MERGEA_QUALIFIER);
HRegionInfo regionB = HRegionInfo.getHRegionInfo(e.getValue(),
HConstants.MERGEB_QUALIFIER);
PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(e.getValue());
HRegionInfo regionA = p.getFirst();
HRegionInfo regionB = p.getSecond();
if (regionA == null || regionB == null) {
LOG.warn("Unexpected references regionA="
+ (regionA == null ? "null" : regionA.getRegionNameAsString())
@ -255,8 +254,10 @@ public class CatalogJanitor extends ScheduledChore {
cleanParent(e.getKey(), e.getValue())) {
splitCleaned++;
} else {
// We could not clean the parent, so it's daughters should not be cleaned either (HBASE-6160)
PairOfSameType<HRegionInfo> daughters = HRegionInfo.getDaughterRegions(e.getValue());
// We could not clean the parent, so it's daughters should not be
// cleaned either (HBASE-6160)
PairOfSameType<HRegionInfo> daughters =
MetaTableAccessor.getDaughterRegions(e.getValue());
parentNotCleaned.add(daughters.getFirst().getEncodedName());
parentNotCleaned.add(daughters.getSecond().getEncodedName());
}
@ -322,7 +323,7 @@ public class CatalogJanitor extends ScheduledChore {
return result;
}
// Run checks on each daughter split.
PairOfSameType<HRegionInfo> daughters = HRegionInfo.getDaughterRegions(rowContent);
PairOfSameType<HRegionInfo> daughters = MetaTableAccessor.getDaughterRegions(rowContent);
Pair<Boolean, Boolean> a = checkDaughterInFs(parent, daughters.getFirst());
Pair<Boolean, Boolean> b = checkDaughterInFs(parent, daughters.getSecond());
if (hasNoReferences(a) && hasNoReferences(b)) {

View File

@ -1949,7 +1949,9 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
if (data == null || data.size() <= 0) {
return true;
}
Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(data);
Pair<HRegionInfo, ServerName> pair =
new Pair(MetaTableAccessor.getHRegionInfo(data),
MetaTableAccessor.getServerName(data,0));
if (pair == null) {
return false;
}

View File

@ -65,9 +65,9 @@ public class RegionStateStore {
/**
* Returns the {@link ServerName} from catalog table {@link Result}
* where the region is transitioning. It should be the same as
* {@link HRegionInfo#getServerName(Result)} if the server is at OPEN state.
* {@link MetaTableAccessor#getServerName(Result,int)} if the server is at OPEN state.
* @param r Result to pull the transitioning server name from
* @return A ServerName instance or {@link HRegionInfo#getServerName(Result)}
* @return A ServerName instance or {@link MetaTableAccessor#getServerName(Result,int)}
* if necessary fields not found or empty.
*/
static ServerName getRegionServer(final Result r, int replicaId) {

View File

@ -3417,7 +3417,7 @@ public class HBaseFsck extends Configured implements Closeable {
|| hri.isMetaRegion())) {
return true;
}
PairOfSameType<HRegionInfo> daughters = HRegionInfo.getDaughterRegions(result);
PairOfSameType<HRegionInfo> daughters = MetaTableAccessor.getDaughterRegions(result);
for (HRegionLocation h : rl.getRegionLocations()) {
if (h == null || h.getRegionInfo() == null) {
continue;
@ -3440,7 +3440,7 @@ public class HBaseFsck extends Configured implements Closeable {
throw new IOException("Two entries in hbase:meta are same " + previous);
}
}
PairOfSameType<HRegionInfo> mergeRegions = HRegionInfo.getMergeRegions(result);
PairOfSameType<HRegionInfo> mergeRegions = MetaTableAccessor.getMergeRegions(result);
for (HRegionInfo mergeRegion : new HRegionInfo[] {
mergeRegions.getFirst(), mergeRegions.getSecond() }) {
if (mergeRegion != null) {

View File

@ -259,7 +259,7 @@ class HMerge {
if (results == null) {
return null;
}
HRegionInfo region = HRegionInfo.getHRegionInfo(results);
HRegionInfo region = MetaTableAccessor.getHRegionInfo(results);
if (region == null) {
throw new NoSuchElementException("meta region entry missing " +
Bytes.toString(HConstants.CATALOG_FAMILY) + ":" +
@ -293,7 +293,7 @@ class HMerge {
currentRow = metaScanner.next();
continue;
}
HRegionInfo region = HRegionInfo.getHRegionInfo(currentRow);
HRegionInfo region = MetaTableAccessor.getHRegionInfo(currentRow);
if (!region.getTable().equals(this.tableName)) {
currentRow = metaScanner.next();
continue;

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
@ -124,7 +125,7 @@ public class Merge extends Configured implements Tool {
Result result1 = meta.get(get);
Preconditions.checkState(!result1.isEmpty(),
"First region cells can not be null");
HRegionInfo info1 = HRegionInfo.getHRegionInfo(result1);
HRegionInfo info1 = MetaTableAccessor.getHRegionInfo(result1);
if (info1 == null) {
throw new NullPointerException("info1 is null using key " +
Bytes.toStringBinary(region1) + " in " + meta);
@ -134,7 +135,7 @@ public class Merge extends Configured implements Tool {
Result result2 = meta.get(get);
Preconditions.checkState(!result2.isEmpty(),
"Second region cells can not be null");
HRegionInfo info2 = HRegionInfo.getHRegionInfo(result2);
HRegionInfo info2 = MetaTableAccessor.getHRegionInfo(result2);
if (info2 == null) {
throw new NullPointerException("info2 is null using key " + meta);
}

View File

@ -2333,7 +2333,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
List<byte[]> rows = new ArrayList<byte[]>();
ResultScanner s = t.getScanner(new Scan());
for (Result result : s) {
HRegionInfo info = HRegionInfo.getHRegionInfo(result);
HRegionInfo info = MetaTableAccessor.getHRegionInfo(result);
if (info == null) {
LOG.error("No region info for row " + Bytes.toString(result.getRow()));
// TODO figure out what to do for this new hosed case.

View File

@ -85,29 +85,29 @@ public class TestMetaTableAccessorNoCluster {
@Test
public void testGetHRegionInfo() throws IOException {
assertNull(HRegionInfo.getHRegionInfo(new Result()));
assertNull(MetaTableAccessor.getHRegionInfo(new Result()));
List<Cell> kvs = new ArrayList<Cell>();
Result r = Result.create(kvs);
assertNull(HRegionInfo.getHRegionInfo(r));
assertNull(MetaTableAccessor.getHRegionInfo(r));
byte [] f = HConstants.CATALOG_FAMILY;
// Make a key value that doesn't have the expected qualifier.
kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f,
HConstants.SERVER_QUALIFIER, f));
r = Result.create(kvs);
assertNull(HRegionInfo.getHRegionInfo(r));
assertNull(MetaTableAccessor.getHRegionInfo(r));
// Make a key that does not have a regioninfo value.
kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f,
HConstants.REGIONINFO_QUALIFIER, f));
HRegionInfo hri = HRegionInfo.getHRegionInfo(Result.create(kvs));
HRegionInfo hri = MetaTableAccessor.getHRegionInfo(Result.create(kvs));
assertTrue(hri == null);
// OK, give it what it expects
kvs.clear();
kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f,
HConstants.REGIONINFO_QUALIFIER,
HRegionInfo.FIRST_META_REGIONINFO.toByteArray()));
hri = HRegionInfo.getHRegionInfo(Result.create(kvs));
hri = MetaTableAccessor.getHRegionInfo(Result.create(kvs));
assertNotNull(hri);
assertTrue(hri.equals(HRegionInfo.FIRST_META_REGIONINFO));
}

View File

@ -291,7 +291,7 @@ public class TestMasterOperationsForRegionReplicas {
Visitor visitor = new Visitor() {
@Override
public boolean visit(Result r) throws IOException {
if (HRegionInfo.getHRegionInfo(r).getTable().equals(table)) count.incrementAndGet();
if (MetaTableAccessor.getHRegionInfo(r).getTable().equals(table)) count.incrementAndGet();
return true;
}
};

View File

@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put;
@ -490,7 +491,7 @@ public class TestMasterTransitions {
scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
ResultScanner s = meta.getScanner(scan);
for (Result r = null; (r = s.next()) != null;) {
HRegionInfo hri = HRegionInfo.getHRegionInfo(r);
HRegionInfo hri = MetaTableAccessor.getHRegionInfo(r);
if (hri == null) break;
if (!hri.getTable().equals(TABLENAME)) {
continue;

View File

@ -224,10 +224,9 @@ public class TestRegionMergeTransactionOnCluster {
HConstants.MERGEB_QUALIFIER) != null);
// merging regions' directory are in the file system all the same
HRegionInfo regionA = HRegionInfo.getHRegionInfo(mergedRegionResult,
HConstants.MERGEA_QUALIFIER);
HRegionInfo regionB = HRegionInfo.getHRegionInfo(mergedRegionResult,
HConstants.MERGEB_QUALIFIER);
PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(mergedRegionResult);
HRegionInfo regionA = p.getFirst();
HRegionInfo regionB = p.getSecond();
FileSystem fs = master.getMasterFileSystem().getFileSystem();
Path rootDir = master.getMasterFileSystem().getRootDir();

View File

@ -248,7 +248,7 @@ public class OfflineMetaRebuildTestCore {
List<Delete> dels = new ArrayList<Delete>();
for (Result r : scanner) {
HRegionInfo info =
HRegionInfo.getHRegionInfo(r);
MetaTableAccessor.getHRegionInfo(r);
if(info != null && !info.getTable().getNamespaceAsString()
.equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) {
Delete d = new Delete(r.getRow());

View File

@ -58,6 +58,7 @@ import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
@ -1682,7 +1683,7 @@ public class ThriftServerRunner implements Runnable {
}
// find region start and end keys
HRegionInfo regionInfo = HRegionInfo.getHRegionInfo(startRowResult);
HRegionInfo regionInfo = MetaTableAccessor.getHRegionInfo(startRowResult);
if (regionInfo == null) {
throw new IOException("HRegionInfo REGIONINFO was null or " +
" empty in Meta for row="
@ -1696,7 +1697,7 @@ public class ThriftServerRunner implements Runnable {
region.version = HREGION_VERSION; // version not used anymore, PB encoding used.
// find region assignment to server
ServerName serverName = HRegionInfo.getServerName(startRowResult);
ServerName serverName = MetaTableAccessor.getServerName(startRowResult, 0);
if (serverName != null) {
region.setServerName(Bytes.toBytes(serverName.getHostname()));
region.port = serverName.getPort();