You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/12/08 01:24:22 UTC

svn commit: r888202 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/HBaseConfiguration.java src/java/org/apache/hadoop/hbase/client/HConnectionManager.java

Author: stack
Date: Tue Dec  8 00:24:21 2009
New Revision: 888202

URL: http://svn.apache.org/viewvc?rev=888202&view=rev
Log:
HBASE-2027 HConnectionManager.HBASE_INSTANCES leaks TableServers

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HBaseConfiguration.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=888202&r1=888201&r2=888202&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Dec  8 00:24:21 2009
@@ -219,6 +219,8 @@
    HBASE-2019  [EC2] remember credentials if not configured
    HBASE-2029  Reduce shell exception dump on console
                (Lars George and J-D via Stack)
+   HBASE-2027  HConnectionManager.HBASE_INSTANCES leaks TableServers
+               (Dave Latham via Stack)
 
   NEW FEATURES
    HBASE-1901  "General" partitioner for "hbase-48" bulk (behind the api, write

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HBaseConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HBaseConfiguration.java?rev=888202&r1=888201&r2=888202&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HBaseConfiguration.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HBaseConfiguration.java Tue Dec  8 00:24:21 2009
@@ -52,7 +52,7 @@
   
   /**
    * Returns the hash code value for this HBaseConfiguration. The hash code of a
-   * HBaseConfiguration is defined by the sum of the hash codes of its entries.
+   * HBaseConfiguration is defined by the xor of the hash codes of its entries.
    * 
    * @see Configuration#iterator() How the entries are obtained.
    */
@@ -66,5 +66,32 @@
     }
     return hash;
   }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (!(obj instanceof HBaseConfiguration))
+      return false;
+    
+    HBaseConfiguration otherConf = (HBaseConfiguration) obj;
+    if (size() != otherConf.size()) {
+      return false;
+    }
+    Iterator<Entry<String, String>> propertyIterator = this.iterator();
+    while (propertyIterator.hasNext()) {
+      Entry<String, String> entry = propertyIterator.next();
+      String key = entry.getKey();
+      String value = entry.getValue();
+      if (!value.equals(otherConf.getRaw(key))) {
+        return false;
+      }
+    }
+    
+    return true;
+  }
+  
   
 }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=888202&r1=888201&r2=888202&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java Tue Dec  8 00:24:21 2009
@@ -24,10 +24,10 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeSet;
-import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.logging.Log;
@@ -85,12 +85,20 @@
     super();
   }
   
-  // A Map of master HBaseConfiguration -> connection information for that 
-  // instance. Note that although the Map is synchronized, the objects it 
-  // contains are mutable and hence require synchronized access to them
+  private static final int MAX_CACHED_HBASE_INSTANCES=31;
+  // A LRU Map of master HBaseConfiguration -> connection information for that 
+  // instance. The objects it contains are mutable and hence require
+  // synchronized access to them.  We set instances to 31.  The zk default max
+  // connections is 30 so should run into zk issues before hit this value of 31.
   private static 
   final Map<HBaseConfiguration, TableServers> HBASE_INSTANCES =
-    new WeakHashMap<HBaseConfiguration, TableServers>();
+    new LinkedHashMap<HBaseConfiguration, TableServers>
+      ((int) (MAX_CACHED_HBASE_INSTANCES/0.75F)+1, 0.75F, true) {
+      @Override
+      protected boolean removeEldestEntry(Map.Entry<HBaseConfiguration, TableServers> eldest) {
+        return size() > MAX_CACHED_HBASE_INSTANCES;
+      }
+  };
   
   private static final Map<String, ClientZKWatcher> ZK_WRAPPERS = 
     new HashMap<String, ClientZKWatcher>();