HBASE-9983 Lower the memory footprint of HRegionLocation
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1542694 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c6e6ab4e3e
commit
cd2db482bc
|
@ -52,6 +52,10 @@ import com.google.protobuf.ZeroCopyLiteralByteString;
|
|||
/**
|
||||
* HRegion information.
|
||||
* Contains HRegion id, start and end keys, a reference to this HRegions' table descriptor, etc.
|
||||
*
|
||||
* On a big cluster, each client will have thousands of instances of this object, often
|
||||
* 100 000 of them if not million. It's important to keep the object size as small
|
||||
* as possible.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Evolving
|
||||
|
@ -179,13 +183,12 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
private boolean offLine = false;
|
||||
private long regionId = -1;
|
||||
private transient byte [] regionName = HConstants.EMPTY_BYTE_ARRAY;
|
||||
private String regionNameStr = "";
|
||||
private boolean split = false;
|
||||
private byte [] startKey = HConstants.EMPTY_BYTE_ARRAY;
|
||||
private int hashCode = -1;
|
||||
//TODO: Move NO_HASH to HStoreFile which is really the only place it is used.
|
||||
public static final String NO_HASH = null;
|
||||
private volatile String encodedName = NO_HASH;
|
||||
private String encodedName = null;
|
||||
private byte [] encodedNameAsBytes = null;
|
||||
|
||||
// Current TableName
|
||||
|
@ -217,7 +220,6 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
// Note: First Meta regions names are still in old format
|
||||
this.regionName = createRegionName(tableName, null,
|
||||
regionId, false);
|
||||
this.regionNameStr = Bytes.toStringBinary(this.regionName);
|
||||
setHashCode();
|
||||
}
|
||||
|
||||
|
@ -289,7 +291,6 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
|
||||
this.regionName = createRegionName(this.tableName, startKey, regionId, true);
|
||||
|
||||
this.regionNameStr = Bytes.toStringBinary(this.regionName);
|
||||
this.split = split;
|
||||
this.endKey = endKey == null? HConstants.EMPTY_END_ROW: endKey.clone();
|
||||
this.startKey = startKey == null?
|
||||
|
@ -309,7 +310,6 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
this.offLine = other.isOffline();
|
||||
this.regionId = other.getRegionId();
|
||||
this.regionName = other.getRegionName();
|
||||
this.regionNameStr = Bytes.toStringBinary(this.regionName);
|
||||
this.split = other.isSplit();
|
||||
this.startKey = other.getStartKey();
|
||||
this.hashCode = other.hashCode();
|
||||
|
@ -499,18 +499,18 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
public String getRegionNameAsString() {
|
||||
if (hasEncodedName(this.regionName)) {
|
||||
// new format region names already have their encoded name.
|
||||
return this.regionNameStr;
|
||||
return Bytes.toStringBinary(this.regionName);
|
||||
}
|
||||
|
||||
// old format. regionNameStr doesn't have the region name.
|
||||
//
|
||||
//
|
||||
return this.regionNameStr + "." + this.getEncodedName();
|
||||
return Bytes.toStringBinary(this.regionName) + "." + this.getEncodedName();
|
||||
}
|
||||
|
||||
/** @return the encoded region name */
|
||||
public synchronized String getEncodedName() {
|
||||
if (this.encodedName == NO_HASH) {
|
||||
if (this.encodedName == null) {
|
||||
this.encodedName = encodeRegionName(this.regionName);
|
||||
}
|
||||
return this.encodedName;
|
||||
|
@ -648,7 +648,7 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "{ENCODED => " + getEncodedName() + ", " +
|
||||
HConstants.NAME + " => '" + this.regionNameStr
|
||||
HConstants.NAME + " => '" + Bytes.toStringBinary(this.regionName)
|
||||
+ "', STARTKEY => '" +
|
||||
Bytes.toStringBinary(this.startKey) + "', ENDKEY => '" +
|
||||
Bytes.toStringBinary(this.endKey) + "'" +
|
||||
|
@ -722,7 +722,6 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
this.offLine = in.readBoolean();
|
||||
this.regionId = in.readLong();
|
||||
this.regionName = Bytes.readByteArray(in);
|
||||
this.regionNameStr = Bytes.toStringBinary(this.regionName);
|
||||
this.split = in.readBoolean();
|
||||
this.startKey = Bytes.readByteArray(in);
|
||||
try {
|
||||
|
@ -738,7 +737,6 @@ public class HRegionInfo implements Comparable<HRegionInfo> {
|
|||
this.offLine = in.readBoolean();
|
||||
this.regionId = in.readLong();
|
||||
this.regionName = Bytes.readByteArray(in);
|
||||
this.regionNameStr = Bytes.toStringBinary(this.regionName);
|
||||
this.split = in.readBoolean();
|
||||
this.startKey = Bytes.readByteArray(in);
|
||||
this.tableName = TableName.valueOf(Bytes.readByteArray(in));
|
||||
|
|
|
@ -28,6 +28,10 @@ import org.apache.hadoop.hbase.util.Addressing;
|
|||
* i.e. the hostname and port, and *not* the regioninfo. This means two
|
||||
* instances are the same if they refer to the same 'location' (the same
|
||||
* hostname and port), though they may be carrying different regions.
|
||||
*
|
||||
* On a big cluster, each client will have thousands of instances of this object, often
|
||||
* 100 000 of them if not million. It's important to keep the object size as small
|
||||
* as possible.
|
||||
*/
|
||||
@InterfaceAudience.Public
|
||||
@InterfaceStability.Evolving
|
||||
|
@ -35,10 +39,6 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
|
|||
private final HRegionInfo regionInfo;
|
||||
private final ServerName serverName;
|
||||
private final long seqNum;
|
||||
// Cache of the 'toString' result.
|
||||
private String cachedString = null;
|
||||
// Cache of the hostname + port
|
||||
private String cachedHostnamePort;
|
||||
|
||||
public HRegionLocation(HRegionInfo regionInfo, ServerName serverName) {
|
||||
this(regionInfo, serverName, HConstants.NO_SEQNUM);
|
||||
|
@ -54,12 +54,9 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
|
|||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public synchronized String toString() {
|
||||
if (this.cachedString == null) {
|
||||
this.cachedString = "region=" + this.regionInfo.getRegionNameAsString() +
|
||||
", hostname=" + this.serverName + ", seqNum=" + seqNum;
|
||||
}
|
||||
return this.cachedString;
|
||||
public String toString() {
|
||||
return "region=" + this.regionInfo.getRegionNameAsString() +
|
||||
", hostname=" + this.serverName + ", seqNum=" + seqNum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,12 +104,8 @@ public class HRegionLocation implements Comparable<HRegionLocation> {
|
|||
/**
|
||||
* @return String made of hostname and port formatted as per {@link Addressing#createHostAndPortStr(String, int)}
|
||||
*/
|
||||
public synchronized String getHostnamePort() {
|
||||
if (this.cachedHostnamePort == null) {
|
||||
this.cachedHostnamePort =
|
||||
Addressing.createHostAndPortStr(this.getHostname(), this.getPort());
|
||||
}
|
||||
return this.cachedHostnamePort;
|
||||
public String getHostnamePort() {
|
||||
return Addressing.createHostAndPortStr(this.getHostname(), this.getPort());
|
||||
}
|
||||
|
||||
public ServerName getServerName() {
|
||||
|
|
|
@ -179,7 +179,7 @@ class AsyncProcess<CResult> {
|
|||
|
||||
throwables.add(ex);
|
||||
actions.add(row);
|
||||
addresses.add(location != null ? location.getHostnamePort() : "null location");
|
||||
addresses.add(location != null ? location.getServerName().toString() : "null location");
|
||||
}
|
||||
|
||||
private synchronized RetriesExhaustedWithDetailsException makeException() {
|
||||
|
|
|
@ -212,8 +212,7 @@ public class ScannerCallable extends RegionServerCallable<Result[]> {
|
|||
HRegionLocation location =
|
||||
getConnection().relocateRegion(getTableName(), scan.getStartRow());
|
||||
LOG.info("Scanner=" + scannerId
|
||||
+ " expired, current region location is " + location.toString()
|
||||
+ " ip:" + location.getHostnamePort());
|
||||
+ " expired, current region location is " + location.toString());
|
||||
} catch (Throwable t) {
|
||||
LOG.info("Failed to relocate region", t);
|
||||
}
|
||||
|
@ -304,8 +303,7 @@ public class ScannerCallable extends RegionServerCallable<Result[]> {
|
|||
long id = response.getScannerId();
|
||||
if (logScannerActivity) {
|
||||
LOG.info("Open scanner=" + id + " for scan=" + scan.toString()
|
||||
+ " on region " + getLocation().toString() + " ip:"
|
||||
+ getLocation().getHostnamePort());
|
||||
+ " on region " + getLocation().toString());
|
||||
}
|
||||
return id;
|
||||
} catch (ServiceException se) {
|
||||
|
|
Loading…
Reference in New Issue