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:
parent
7461f767a6
commit
d67d131f10
|
@ -40,6 +40,8 @@ Release 0.20.0 - Unreleased
|
|||
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
|
||||
|
|
|
@ -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 @@ public class HBaseConfiguration extends Configuration {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.HashMap;
|
|||
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.client.MetaScanner.MetaScannerVisitor;
|
|||
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 @@ public class HConnectionManager implements HConstants {
|
|||
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 class HConnectionManager implements HConstants {
|
|||
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 class HConnectionManager implements HConstants {
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue