diff --git a/CHANGES.txt b/CHANGES.txt index 877d2507c2..ff37b02b3f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java b/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java index a247bf99e6..5d8329ac40 100644 --- a/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java +++ b/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java @@ -50,7 +50,6 @@ * 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 @@ static MetricsConfig loadFirst(String prefix, String... fileNames) { 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 diff --git a/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java b/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java index da95e32a1e..d90ec74358 100644 --- a/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java +++ b/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java @@ -154,7 +154,7 @@ public synchronized MetricsSystem init(String prefix) { 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 @@ private void initSystemMBean() { @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(); } diff --git a/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java b/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java index 83c253665f..a720b24bf2 100644 --- a/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java +++ b/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java @@ -109,18 +109,11 @@ private void testInstances(MetricsConfig c) throws Exception { } /** - * 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()); } /**