HADOOP-7306. Start metrics system even if config files are missing. Contributed by Luke Lu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1125216 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2011-05-20 03:22:03 +00:00
parent 2a0bbd9979
commit 4977f4bfe3
4 changed files with 15 additions and 15 deletions

View File

@ -167,6 +167,9 @@ Trunk (unreleased changes)
HADOOP-7301. FSDataInputStream should expose a getWrappedStream method. HADOOP-7301. FSDataInputStream should expose a getWrappedStream method.
(Jonathan Hsieh via eli) (Jonathan Hsieh via eli)
HADOOP-7306. Start metrics system even if config files are missing
(Luke Lu via todd)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -50,7 +50,6 @@ import org.apache.hadoop.metrics2.filter.GlobFilter;
* Metrics configuration for MetricsSystemImpl * Metrics configuration for MetricsSystemImpl
*/ */
class MetricsConfig extends SubsetConfiguration { class MetricsConfig extends SubsetConfiguration {
static final Log LOG = LogFactory.getLog(MetricsConfig.class); static final Log LOG = LogFactory.getLog(MetricsConfig.class);
static final String DEFAULT_FILE_NAME = "hadoop-metrics2.properties"; static final String DEFAULT_FILE_NAME = "hadoop-metrics2.properties";
@ -123,8 +122,10 @@ class MetricsConfig extends SubsetConfiguration {
throw new MetricsConfigException(e); throw new MetricsConfigException(e);
} }
} }
throw new MetricsConfigException("Cannot locate configuration: tried "+ LOG.warn("Cannot locate configuration: tried "+
Joiner.on(",").join(fileNames)); Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
} }
@Override @Override

View File

@ -154,7 +154,7 @@ public class MetricsSystemImpl extends MetricsSystem implements MetricsSource {
case NORMAL: case NORMAL:
try { start(); } try { start(); }
catch (MetricsConfigException e) { 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. // We can always start the metrics system later via JMX.
LOG.warn("Metrics system not started: "+ e.getMessage()); LOG.warn("Metrics system not started: "+ e.getMessage());
LOG.debug("Stacktrace: ", e); LOG.debug("Stacktrace: ", e);
@ -532,7 +532,10 @@ public class MetricsSystemImpl extends MetricsSystem implements MetricsSource {
@Override @Override
public synchronized boolean shutdown() { public synchronized boolean shutdown() {
LOG.debug("refCount="+ refCount); 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 (--refCount > 0) return false;
if (monitoring) { if (monitoring) {
try { stop(); } try { stop(); }

View File

@ -109,18 +109,11 @@ public class TestMetricsConfig {
} }
/** /**
* Should throw if missing config files * Should not throw if missing config files
*/ */
@Test public void testMissingFiles() { @Test public void testMissingFiles() {
try { MetricsConfig config = MetricsConfig.create("JobTracker", "non-existent.properties");
MetricsConfig.create("JobTracker", "non-existent.properties"); assertTrue(config.isEmpty());
}
catch (MetricsConfigException e) {
assertTrue("expected the 'cannot locate configuration' exception",
e.getMessage().startsWith("Cannot locate configuration"));
return;
}
fail("should've thrown");
} }
/** /**