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/03/13 17:07:35 UTC

svn commit: r753308 - 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: Fri Mar 13 16:07:35 2009
New Revision: 753308

URL: http://svn.apache.org/viewvc?rev=753308&view=rev
Log:
HBASE-1251 HConnectionManager.getConnection(HBaseConfiguration) returns same HConnection for different HBaseConfigurations

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=753308&r1=753307&r2=753308&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Fri Mar 13 16:07:35 2009
@@ -40,6 +40,8 @@
    HBASE-1247  checkAndSave doesn't Write Ahead Log
    HBASE-1243  oldlogfile.dat is screwed, so is it's region
    HBASE-1169  When a shutdown is requested, stop scanning META regions immediately
+   HBASE-1251  HConnectionManager.getConnection(HBaseConfiguration) returns same
+               HConnection for different HBaseConfigurations 
 
   IMPROVEMENTS
    HBASE-1089  Add count of regions on filesystem to master UI; add percentage

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=753308&r1=753307&r2=753308&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 Fri Mar 13 16:07:35 2009
@@ -19,6 +19,7 @@
  */
 package org.apache.hadoop.hbase;
 
+import java.util.Iterator;
 import java.util.Map.Entry;
 
 import org.apache.hadoop.conf.Configuration;
@@ -48,4 +49,22 @@
     addResource("hbase-default.xml");
     addResource("hbase-site.xml");
   }
+  
+  /**
+   * 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.
+   * 
+   * @see Configuration#iterator() How the entries are obtained.
+   */
+  @Override
+  public int hashCode() {
+    int hash = 0;
+
+    Iterator<Entry<String, String>> propertyIterator = this.iterator();
+    while (propertyIterator.hasNext()) {
+      hash ^= propertyIterator.next().hashCode();
+    }
+    return hash;
+  }
+  
 }

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=753308&r1=753307&r2=753308&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 Fri Mar 13 16:07:35 2009
@@ -27,6 +27,7 @@
 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;
@@ -47,10 +48,10 @@
 import org.apache.hadoop.hbase.io.BatchUpdate;
 import org.apache.hadoop.hbase.io.Cell;
 import org.apache.hadoop.hbase.io.RowResult;
+import org.apache.hadoop.hbase.ipc.HBaseRPC;
 import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
-import org.apache.hadoop.hbase.ipc.HBaseRPC;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.MetaUtils;
 import org.apache.hadoop.hbase.util.SoftValueSortedMap;
@@ -73,12 +74,13 @@
     super();
   }
   
-  // A Map of master HServerAddress -> 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 Map<String, TableServers> HBASE_INSTANCES =
-    new ConcurrentHashMap<String, TableServers>();
-
+  // 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 Map<HBaseConfiguration, TableServers> HBASE_INSTANCES = 
+    new WeakHashMap<HBaseConfiguration, TableServers>();
+  
   /**
    * Get the connection object for the instance specified by the configuration
    * If no current connection exists, create a new connection for that instance
@@ -88,11 +90,10 @@
   public static HConnection getConnection(HBaseConfiguration conf) {
     TableServers connection;
     synchronized (HBASE_INSTANCES) {
-      String instanceName = conf.get(HBASE_DIR);
-      connection = HBASE_INSTANCES.get(instanceName);
+      connection = HBASE_INSTANCES.get(conf);
       if (connection == null) {
         connection = new TableServers(conf);
-        HBASE_INSTANCES.put(instanceName, connection);
+        HBASE_INSTANCES.put(conf, connection);
       }
     }
     return connection;
@@ -106,7 +107,7 @@
   public static void deleteConnectionInfo(HBaseConfiguration conf,
       boolean stopProxy) {
     synchronized (HBASE_INSTANCES) {
-      TableServers t = HBASE_INSTANCES.remove(conf.get(HBASE_DIR));
+      TableServers t = HBASE_INSTANCES.remove(conf);
       if (t != null) {
         t.close(stopProxy);
       }