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

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1291081 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Foley 2012-02-19 22:39:50 +00:00
parent 1705035963
commit 197d6d34ca
2 changed files with 43 additions and 22 deletions

View File

@ -60,6 +60,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,9 +94,10 @@ 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();
synchronized(this) {
Attribute a = attrCache.get(attribute); Attribute a = attrCache.get(attribute);
if (a == null) { if (a == null) {
throw new AttributeNotFoundException(attribute +" not found"); throw new AttributeNotFoundException(attribute +" not found");
@ -106,6 +107,7 @@ class MetricsSourceAdapter implements DynamicMBean {
} }
return a.getValue(); return a.getValue();
} }
}
@Override @Override
public void setAttribute(Attribute attribute) public void setAttribute(Attribute attribute)
@ -115,8 +117,9 @@ class MetricsSourceAdapter implements DynamicMBean {
} }
@Override @Override
public synchronized AttributeList getAttributes(String[] attributes) { public AttributeList getAttributes(String[] attributes) {
updateJmxCache(); updateJmxCache();
synchronized(this) {
AttributeList ret = new AttributeList(); AttributeList ret = new AttributeList();
for (String key : attributes) { for (String key : attributes) {
Attribute attr = attrCache.get(key); Attribute attr = attrCache.get(key);
@ -127,6 +130,7 @@ class MetricsSourceAdapter implements DynamicMBean {
} }
return ret; return ret;
} }
}
@Override @Override
public AttributeList setAttributes(AttributeList attributes) { public AttributeList setAttributes(AttributeList attributes) {
@ -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() {
boolean getAllMetrics = false;
synchronized(this) {
if (System.currentTimeMillis() - jmxCacheTS >= jmxCacheTTL) { if (System.currentTimeMillis() - jmxCacheTS >= jmxCacheTTL) {
// temporarilly advance the expiry while updating the cache
jmxCacheTS = System.currentTimeMillis() + jmxCacheTTL;
if (lastRecs == null) { if (lastRecs == null) {
getAllMetrics = true;
}
}
else {
return;
}
}
if (getAllMetrics) {
MetricsCollectorImpl builder = new MetricsCollectorImpl(); MetricsCollectorImpl builder = new MetricsCollectorImpl();
getMetrics(builder, true); 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) {