HBASE-2027 HConnectionManager.HBASE_INSTANCES leaks TableServers

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@888202 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-12-08 00:24:21 +00:00
parent 28b6d90a93
commit d0b61e75ae
3 changed files with 43 additions and 6 deletions

View File

@ -219,6 +219,8 @@ Release 0.21.0 - Unreleased
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

View File

@ -52,7 +52,7 @@ public class HBaseConfiguration extends Configuration {
/**
* 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 @@ public class HBaseConfiguration extends Configuration {
}
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;
}
}

View File

@ -24,10 +24,10 @@ import java.lang.reflect.UndeclaredThrowableException;
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 @@ public class HConnectionManager implements HConstants {
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>();