You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by to...@apache.org on 2011/05/20 05:22:04 UTC

svn commit: r1125216 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java

Author: todd
Date: Fri May 20 03:22:03 2011
New Revision: 1125216

URL: http://svn.apache.org/viewvc?rev=1125216&view=rev
Log:
HADOOP-7306. Start metrics system even if config files are missing. Contributed by Luke Lu.

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java
    hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1125216&r1=1125215&r2=1125216&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri May 20 03:22:03 2011
@@ -167,6 +167,9 @@ Trunk (unreleased changes)
     HADOOP-7301. FSDataInputStream should expose a getWrappedStream method.
     (Jonathan Hsieh via eli)
 
+    HADOOP-7306. Start metrics system even if config files are missing
+    (Luke Lu via todd)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java?rev=1125216&r1=1125215&r2=1125216&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java Fri May 20 03:22:03 2011
@@ -50,7 +50,6 @@ import org.apache.hadoop.metrics2.filter
  * Metrics configuration for MetricsSystemImpl
  */
 class MetricsConfig extends SubsetConfiguration {
-
   static final Log LOG = LogFactory.getLog(MetricsConfig.class);
 
   static final String DEFAULT_FILE_NAME = "hadoop-metrics2.properties";
@@ -123,8 +122,10 @@ class MetricsConfig extends SubsetConfig
         throw new MetricsConfigException(e);
       }
     }
-    throw new MetricsConfigException("Cannot locate configuration: tried "+
-                                     Joiner.on(",").join(fileNames));
+    LOG.warn("Cannot locate configuration: tried "+
+             Joiner.on(",").join(fileNames));
+    // default to an empty configuration
+    return new MetricsConfig(new PropertiesConfiguration(), prefix);
   }
 
   @Override

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java?rev=1125216&r1=1125215&r2=1125216&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java Fri May 20 03:22:03 2011
@@ -154,7 +154,7 @@ public class MetricsSystemImpl extends M
       case NORMAL:
         try { start(); }
         catch (MetricsConfigException e) {
-          // Usually because hadoop-metrics2.properties is missing
+          // Configuration errors (e.g., typos) should not be fatal.
           // We can always start the metrics system later via JMX.
           LOG.warn("Metrics system not started: "+ e.getMessage());
           LOG.debug("Stacktrace: ", e);
@@ -532,7 +532,10 @@ public class MetricsSystemImpl extends M
   @Override
   public synchronized boolean shutdown() {
     LOG.debug("refCount="+ refCount);
-    if (refCount <= 0) LOG.debug("Redundant shutdown", new Throwable());
+    if (refCount <= 0) {
+      LOG.debug("Redundant shutdown", new Throwable());
+      return true; // already shutdown
+    }
     if (--refCount > 0) return false;
     if (monitoring) {
       try { stop(); }

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java?rev=1125216&r1=1125215&r2=1125216&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java Fri May 20 03:22:03 2011
@@ -109,18 +109,11 @@ public class TestMetricsConfig {
   }
 
   /**
-   * Should throw if missing config files
+   * Should not throw if missing config files
    */
   @Test public void testMissingFiles() {
-    try {
-      MetricsConfig.create("JobTracker", "non-existent.properties");
-    }
-    catch (MetricsConfigException e) {
-      assertTrue("expected the 'cannot locate configuration' exception",
-                 e.getMessage().startsWith("Cannot locate configuration"));
-      return;
-    }
-    fail("should've thrown");
+    MetricsConfig config = MetricsConfig.create("JobTracker", "non-existent.properties");
+    assertTrue(config.isEmpty());
   }
 
   /**