You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nk...@apache.org on 2013/11/17 11:29:01 UTC

svn commit: r1542694 - in /hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase: HRegionInfo.java HRegionLocation.java client/AsyncProcess.java client/ScannerCallable.java

Author: nkeywal
Date: Sun Nov 17 10:29:01 2013
New Revision: 1542694

URL: http://svn.apache.org/r1542694
Log:
HBASE-9983 Lower the memory footprint of HRegionLocation

Modified:
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionLocation.java
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncProcess.java
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java?rev=1542694&r1=1542693&r2=1542694&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java Sun Nov 17 10:29:01 2013
@@ -52,6 +52,10 @@ import com.google.protobuf.ZeroCopyLiter
 /**
  * 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 Comp
   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 Comp
     // 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 Comp
 
     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 Comp
     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 Comp
   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 Comp
   @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 Comp
       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 Comp
       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));

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionLocation.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionLocation.java?rev=1542694&r1=1542693&r2=1542694&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionLocation.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionLocation.java Sun Nov 17 10:29:01 2013
@@ -28,6 +28,10 @@ import org.apache.hadoop.hbase.util.Addr
  * 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 
   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 
    * @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 
   /**
    * @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() {

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncProcess.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncProcess.java?rev=1542694&r1=1542693&r2=1542694&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncProcess.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncProcess.java Sun Nov 17 10:29:01 2013
@@ -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() {

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java?rev=1542694&r1=1542693&r2=1542694&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java Sun Nov 17 10:29:01 2013
@@ -212,8 +212,7 @@ public class ScannerCallable extends Reg
               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 Reg
       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) {