HBASE-8426 Opening a region failed on Metrics source RegionServer,sub=Regions already exists

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1477247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
eclark 2013-04-29 18:17:37 +00:00
parent 6b35308cf0
commit b33878f6fc
3 changed files with 65 additions and 46 deletions

View File

@ -31,8 +31,12 @@ import java.util.ServiceLoader;
* created.
*/
public class CompatibilitySingletonFactory extends CompatibilityFactory {
private static final Log LOG = LogFactory.getLog(CompatibilitySingletonFactory.class);
public static enum SingletonStorage {
INSTANCE;
Object lock = new Object();
private static final Map<Class, Object> instances = new HashMap<Class, Object>();
}
private static final Log LOG = LogFactory.getLog(CompatibilitySingletonFactory.class);
/**
* This is a static only class don't let anyone create an instance.
@ -45,8 +49,9 @@ public class CompatibilitySingletonFactory extends CompatibilityFactory {
* @return the singleton
*/
@SuppressWarnings("unchecked")
public static synchronized <T> T getInstance(Class<T> klass) {
T instance = (T) instances.get(klass);
public static <T> T getInstance(Class<T> klass) {
synchronized (SingletonStorage.INSTANCE.lock) {
T instance = (T) SingletonStorage.INSTANCE.instances.get(klass);
if (instance == null) {
try {
ServiceLoader<T> loader = ServiceLoader.load(klass);
@ -74,8 +79,10 @@ public class CompatibilitySingletonFactory extends CompatibilityFactory {
if (instance == null) {
throw new RuntimeException(createExceptionString(klass));
}
instances.put(klass, instance);
SingletonStorage.INSTANCE.instances.put(klass, instance);
}
return instance;
}
}
}

View File

@ -22,28 +22,34 @@ package org.apache.hadoop.hbase.regionserver;
* Factory to create MetricsRegionServerSource when given a MetricsRegionServerWrapper
*/
public class MetricsRegionServerSourceFactoryImpl implements MetricsRegionServerSourceFactory {
private static enum FactoryStorage {
public static enum FactoryStorage {
INSTANCE;
private Object aggLock = new Object();
private Object serverLock = new Object();
private MetricsRegionServerSource serverSource;
private MetricsRegionAggregateSourceImpl aggImpl;
}
private synchronized MetricsRegionAggregateSourceImpl getAggregate() {
synchronized (FactoryStorage.INSTANCE.aggLock) {
if (FactoryStorage.INSTANCE.aggImpl == null) {
FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
}
return FactoryStorage.INSTANCE.aggImpl;
}
}
@Override
public synchronized MetricsRegionServerSource createServer(MetricsRegionServerWrapper regionServerWrapper) {
synchronized (FactoryStorage.INSTANCE.serverLock) {
if (FactoryStorage.INSTANCE.serverSource == null) {
FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
regionServerWrapper);
}
return FactoryStorage.INSTANCE.serverSource;
}
}
@Override
public MetricsRegionSource createRegion(MetricsRegionWrapper wrapper) {

View File

@ -22,28 +22,34 @@ package org.apache.hadoop.hbase.regionserver;
* Factory to create MetricsRegionServerSource when given a MetricsRegionServerWrapper
*/
public class MetricsRegionServerSourceFactoryImpl implements MetricsRegionServerSourceFactory {
private static enum FactoryStorage {
public static enum FactoryStorage {
INSTANCE;
private Object aggLock = new Object();
private Object serverLock = new Object();
private MetricsRegionServerSource serverSource;
private MetricsRegionAggregateSourceImpl aggImpl;
}
private synchronized MetricsRegionAggregateSourceImpl getAggregate() {
synchronized (FactoryStorage.INSTANCE.aggLock) {
if (FactoryStorage.INSTANCE.aggImpl == null) {
FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
}
return FactoryStorage.INSTANCE.aggImpl;
}
}
@Override
public synchronized MetricsRegionServerSource createServer(MetricsRegionServerWrapper regionServerWrapper) {
synchronized (FactoryStorage.INSTANCE.serverLock) {
if (FactoryStorage.INSTANCE.serverSource == null) {
FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
regionServerWrapper);
}
return FactoryStorage.INSTANCE.serverSource;
}
}
@Override
public MetricsRegionSource createRegion(MetricsRegionWrapper wrapper) {