HBASE-1251 HConnectionManager.getConnection(HBaseConfiguration) returns same HConnection for different HBaseConfigurations

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@753308 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-03-13 16:07:35 +00:00
parent 7461f767a6
commit d67d131f10
3 changed files with 33 additions and 11 deletions

View File

@ -40,6 +40,8 @@ Release 0.20.0 - Unreleased
HBASE-1247 checkAndSave doesn't Write Ahead Log HBASE-1247 checkAndSave doesn't Write Ahead Log
HBASE-1243 oldlogfile.dat is screwed, so is it's region HBASE-1243 oldlogfile.dat is screwed, so is it's region
HBASE-1169 When a shutdown is requested, stop scanning META regions immediately HBASE-1169 When a shutdown is requested, stop scanning META regions immediately
HBASE-1251 HConnectionManager.getConnection(HBaseConfiguration) returns same
HConnection for different HBaseConfigurations
IMPROVEMENTS IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage HBASE-1089 Add count of regions on filesystem to master UI; add percentage

View File

@ -19,6 +19,7 @@
*/ */
package org.apache.hadoop.hbase; package org.apache.hadoop.hbase;
import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -48,4 +49,22 @@ public class HBaseConfiguration extends Configuration {
addResource("hbase-default.xml"); addResource("hbase-default.xml");
addResource("hbase-site.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;
}
} }

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -47,10 +48,10 @@ import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
import org.apache.hadoop.hbase.io.BatchUpdate; import org.apache.hadoop.hbase.io.BatchUpdate;
import org.apache.hadoop.hbase.io.Cell; import org.apache.hadoop.hbase.io.Cell;
import org.apache.hadoop.hbase.io.RowResult; 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.HBaseRPCProtocolVersion;
import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface; 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.Bytes;
import org.apache.hadoop.hbase.util.MetaUtils; import org.apache.hadoop.hbase.util.MetaUtils;
import org.apache.hadoop.hbase.util.SoftValueSortedMap; import org.apache.hadoop.hbase.util.SoftValueSortedMap;
@ -73,12 +74,13 @@ public class HConnectionManager implements HConstants {
super(); super();
} }
// A Map of master HServerAddress -> connection information for that instance // A Map of master HBaseConfiguration -> connection information for that
// Note that although the Map is synchronized, the objects it contains // instance. Note that although the Map is synchronized, the objects it
// are mutable and hence require synchronized access to them // contains are mutable and hence require synchronized access to them
private static final Map<String, TableServers> HBASE_INSTANCES = private static
new ConcurrentHashMap<String, TableServers>(); final Map<HBaseConfiguration, TableServers> HBASE_INSTANCES =
new WeakHashMap<HBaseConfiguration, TableServers>();
/** /**
* Get the connection object for the instance specified by the configuration * Get the connection object for the instance specified by the configuration
* If no current connection exists, create a new connection for that instance * If no current connection exists, create a new connection for that instance
@ -88,11 +90,10 @@ public class HConnectionManager implements HConstants {
public static HConnection getConnection(HBaseConfiguration conf) { public static HConnection getConnection(HBaseConfiguration conf) {
TableServers connection; TableServers connection;
synchronized (HBASE_INSTANCES) { synchronized (HBASE_INSTANCES) {
String instanceName = conf.get(HBASE_DIR); connection = HBASE_INSTANCES.get(conf);
connection = HBASE_INSTANCES.get(instanceName);
if (connection == null) { if (connection == null) {
connection = new TableServers(conf); connection = new TableServers(conf);
HBASE_INSTANCES.put(instanceName, connection); HBASE_INSTANCES.put(conf, connection);
} }
} }
return connection; return connection;
@ -106,7 +107,7 @@ public class HConnectionManager implements HConstants {
public static void deleteConnectionInfo(HBaseConfiguration conf, public static void deleteConnectionInfo(HBaseConfiguration conf,
boolean stopProxy) { boolean stopProxy) {
synchronized (HBASE_INSTANCES) { synchronized (HBASE_INSTANCES) {
TableServers t = HBASE_INSTANCES.remove(conf.get(HBASE_DIR)); TableServers t = HBASE_INSTANCES.remove(conf);
if (t != null) { if (t != null) {
t.close(stopProxy); t.close(stopProxy);
} }