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.
(Jonathan Hsieh via eli)
HADOOP-7306. Start metrics system even if config files are missing
(Luke Lu via todd)
OPTIMIZATIONS
BUG FIXES

View File

@ -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

View File

@ -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(); }

View File

@ -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());
}
/**