hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject svn commit: r1477246 - in /hbase/branches/0.95: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/
Date Mon, 29 Apr 2013 18:17:31 GMT
Author: eclark
Date: Mon Apr 29 18:17:30 2013
New Revision: 1477246

URL: http://svn.apache.org/r1477246
Log:
HBASE-8426 Opening a region failed on Metrics source RegionServer,sub=Regions already exists

Modified:
    hbase/branches/0.95/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java
    hbase/branches/0.95/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
    hbase/branches/0.95/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java

Modified: hbase/branches/0.95/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java?rev=1477246&r1=1477245&r2=1477246&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java
(original)
+++ hbase/branches/0.95/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java
Mon Apr 29 18:17:30 2013
@@ -31,8 +31,12 @@ import java.util.ServiceLoader;
  *  created.
  */
 public class CompatibilitySingletonFactory extends CompatibilityFactory {
+  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);
-  private static final Map<Class, Object> instances = new HashMap<Class, Object>();
 
   /**
    * This is a static only class don't let anyone create an instance.
@@ -45,37 +49,40 @@ public class CompatibilitySingletonFacto
    * @return the singleton
    */
   @SuppressWarnings("unchecked")
-  public static synchronized <T> T getInstance(Class<T> klass) {
-    T instance = (T) instances.get(klass);
-    if (instance == null) {
-      try {
-        ServiceLoader<T> loader = ServiceLoader.load(klass);
-        Iterator<T> it = loader.iterator();
-        instance = it.next();
-        if (it.hasNext()) {
-          StringBuilder msg = new StringBuilder();
-          msg.append("ServiceLoader provided more than one implementation for class: ")
-                  .append(klass)
-                  .append(", using implementation: ").append(instance.getClass())
-                  .append(", other implementations: {");
-          while (it.hasNext()) {
-            msg.append(it.next()).append(" ");
+  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);
+          Iterator<T> it = loader.iterator();
+          instance = it.next();
+          if (it.hasNext()) {
+            StringBuilder msg = new StringBuilder();
+            msg.append("ServiceLoader provided more than one implementation for class: ")
+                .append(klass)
+                .append(", using implementation: ").append(instance.getClass())
+                .append(", other implementations: {");
+            while (it.hasNext()) {
+              msg.append(it.next()).append(" ");
+            }
+            msg.append("}");
+            LOG.warn(msg);
           }
-          msg.append("}");
-          LOG.warn(msg);
+        } catch (Exception e) {
+          throw new RuntimeException(createExceptionString(klass), e);
+        } catch (Error e) {
+          throw new RuntimeException(createExceptionString(klass), e);
         }
-      } catch (Exception e) {
-        throw new RuntimeException(createExceptionString(klass), e);
-      } catch (Error e) {
-        throw new RuntimeException(createExceptionString(klass), e);
-      }
 
-      // If there was nothing returned and no exception then throw an exception.
-      if (instance == null) {
-        throw new RuntimeException(createExceptionString(klass));
+        // If there was nothing returned and no exception then throw an exception.
+        if (instance == null) {
+          throw new RuntimeException(createExceptionString(klass));
+        }
+        SingletonStorage.INSTANCE.instances.put(klass, instance);
       }
-      instances.put(klass, instance);
+      return instance;
     }
-    return instance;
+
   }
 }

Modified: hbase/branches/0.95/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java?rev=1477246&r1=1477245&r2=1477246&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
(original)
+++ hbase/branches/0.95/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
Mon Apr 29 18:17:30 2013
@@ -22,27 +22,33 @@ package org.apache.hadoop.hbase.regionse
  * 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() {
-    if (FactoryStorage.INSTANCE.aggImpl == null) {
-      FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
+    synchronized (FactoryStorage.INSTANCE.aggLock) {
+      if (FactoryStorage.INSTANCE.aggImpl == null) {
+        FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
+      }
+      return FactoryStorage.INSTANCE.aggImpl;
     }
-    return FactoryStorage.INSTANCE.aggImpl;
   }
 
 
   @Override
   public synchronized MetricsRegionServerSource createServer(MetricsRegionServerWrapper regionServerWrapper)
{
-    if (FactoryStorage.INSTANCE.serverSource == null) {
-      FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
-          regionServerWrapper);
+    synchronized (FactoryStorage.INSTANCE.serverLock) {
+      if (FactoryStorage.INSTANCE.serverSource == null) {
+        FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
+            regionServerWrapper);
+      }
+      return FactoryStorage.INSTANCE.serverSource;
     }
-    return FactoryStorage.INSTANCE.serverSource;
   }
 
   @Override

Modified: hbase/branches/0.95/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java?rev=1477246&r1=1477245&r2=1477246&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
(original)
+++ hbase/branches/0.95/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
Mon Apr 29 18:17:30 2013
@@ -22,27 +22,33 @@ package org.apache.hadoop.hbase.regionse
  * 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() {
-    if (FactoryStorage.INSTANCE.aggImpl == null) {
-      FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
+    synchronized (FactoryStorage.INSTANCE.aggLock) {
+      if (FactoryStorage.INSTANCE.aggImpl == null) {
+        FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
+      }
+      return FactoryStorage.INSTANCE.aggImpl;
     }
-    return FactoryStorage.INSTANCE.aggImpl;
   }
 
 
   @Override
   public synchronized MetricsRegionServerSource createServer(MetricsRegionServerWrapper regionServerWrapper)
{
-    if (FactoryStorage.INSTANCE.serverSource == null) {
-      FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
-          regionServerWrapper);
+    synchronized (FactoryStorage.INSTANCE.serverLock) {
+      if (FactoryStorage.INSTANCE.serverSource == null) {
+        FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
+            regionServerWrapper);
+      }
+      return FactoryStorage.INSTANCE.serverSource;
     }
-    return FactoryStorage.INSTANCE.serverSource;
   }
 
   @Override



Mime
View raw message