HADOOP-8050. Deadlock in metrics. Contributed by Kihwal Lee.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1291084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Foley 2012-02-19 22:45:12 +00:00
parent 145338bc44
commit def0ac8060
2 changed files with 43 additions and 22 deletions

View File

@ -212,6 +212,8 @@ Release 0.23.2 - UNRELEASED
HADOOP-7680 TestHardLink fails on Mac OS X, when gnu stat is in path. HADOOP-7680 TestHardLink fails on Mac OS X, when gnu stat is in path.
(Milind Bhandarkar via stevel) (Milind Bhandarkar via stevel)
HADOOP-8050. Deadlock in metrics. (Kihwal Lee via mattf)
Release 0.23.1 - 2012-02-17 Release 0.23.1 - 2012-02-17
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -94,17 +94,19 @@ class MetricsSourceAdapter implements DynamicMBean {
} }
@Override @Override
public synchronized Object getAttribute(String attribute) public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException { throws AttributeNotFoundException, MBeanException, ReflectionException {
updateJmxCache(); updateJmxCache();
Attribute a = attrCache.get(attribute); synchronized(this) {
if (a == null) { Attribute a = attrCache.get(attribute);
throw new AttributeNotFoundException(attribute +" not found"); if (a == null) {
throw new AttributeNotFoundException(attribute +" not found");
}
if (LOG.isDebugEnabled()) {
LOG.debug(attribute +": "+ a);
}
return a.getValue();
} }
if (LOG.isDebugEnabled()) {
LOG.debug(attribute +": "+ a);
}
return a.getValue();
} }
@Override @Override
@ -115,17 +117,19 @@ class MetricsSourceAdapter implements DynamicMBean {
} }
@Override @Override
public synchronized AttributeList getAttributes(String[] attributes) { public AttributeList getAttributes(String[] attributes) {
updateJmxCache(); updateJmxCache();
AttributeList ret = new AttributeList(); synchronized(this) {
for (String key : attributes) { AttributeList ret = new AttributeList();
Attribute attr = attrCache.get(key); for (String key : attributes) {
if (LOG.isDebugEnabled()) { Attribute attr = attrCache.get(key);
LOG.debug(key +": "+ attr); if (LOG.isDebugEnabled()) {
LOG.debug(key +": "+ attr);
}
ret.add(attr);
} }
ret.add(attr); return ret;
} }
return ret;
} }
@Override @Override
@ -140,17 +144,32 @@ class MetricsSourceAdapter implements DynamicMBean {
} }
@Override @Override
public synchronized MBeanInfo getMBeanInfo() { public MBeanInfo getMBeanInfo() {
updateJmxCache(); updateJmxCache();
return infoCache; return infoCache;
} }
private synchronized void updateJmxCache() { private void updateJmxCache() {
if (System.currentTimeMillis() - jmxCacheTS >= jmxCacheTTL) { boolean getAllMetrics = false;
if (lastRecs == null) { synchronized(this) {
MetricsCollectorImpl builder = new MetricsCollectorImpl(); if (System.currentTimeMillis() - jmxCacheTS >= jmxCacheTTL) {
getMetrics(builder, true); // temporarilly advance the expiry while updating the cache
jmxCacheTS = System.currentTimeMillis() + jmxCacheTTL;
if (lastRecs == null) {
getAllMetrics = true;
}
} }
else {
return;
}
}
if (getAllMetrics) {
MetricsCollectorImpl builder = new MetricsCollectorImpl();
getMetrics(builder, true);
}
synchronized(this) {
int oldCacheSize = attrCache.size(); int oldCacheSize = attrCache.size();
int newCacheSize = updateAttrCache(); int newCacheSize = updateAttrCache();
if (oldCacheSize < newCacheSize) { if (oldCacheSize < newCacheSize) {