HADOOP-10337 ConcurrentModificationException from MetricsDynamicMBeanBase.createMBeanInfo() (Liang Xie via stack)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1576187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2014-03-11 04:34:13 +00:00
parent 98ecd4ffef
commit 66cde6a17f
2 changed files with 13 additions and 10 deletions

View File

@ -417,6 +417,9 @@ Release 2.4.0 - UNRELEASED
HADOOP-10394. TestAuthenticationFilter is flaky. (Arpit Agarwal) HADOOP-10394. TestAuthenticationFilter is flaky. (Arpit Agarwal)
HADOOP-10337 ConcurrentModificationException from
MetricsDynamicMBeanBase.createMBeanInfo() (Liang Xie via stack)
BREAKDOWN OF HADOOP-10184 SUBTASKS AND RELATED JIRAS BREAKDOWN OF HADOOP-10184 SUBTASKS AND RELATED JIRAS
HADOOP-10185. FileSystem API for ACLs. (cnauroth) HADOOP-10185. FileSystem API for ACLs. (cnauroth)

View File

@ -18,8 +18,7 @@
package org.apache.hadoop.metrics.util; package org.apache.hadoop.metrics.util;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
@ -32,7 +31,8 @@
*/ */
@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"}) @InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
public class MetricsRegistry { public class MetricsRegistry {
private Map<String, MetricsBase> metricsList = new HashMap<String, MetricsBase>(); private ConcurrentHashMap<String, MetricsBase> metricsList =
new ConcurrentHashMap<String, MetricsBase>();
public MetricsRegistry() { public MetricsRegistry() {
} }
@ -51,11 +51,11 @@ public int size() {
* @param theMetricsObj - the metrics * @param theMetricsObj - the metrics
* @throws IllegalArgumentException if a name is already registered * @throws IllegalArgumentException if a name is already registered
*/ */
public synchronized void add(final String metricsName, final MetricsBase theMetricsObj) { public void add(final String metricsName, final MetricsBase theMetricsObj) {
if (metricsList.containsKey(metricsName)) { if (metricsList.putIfAbsent(metricsName, theMetricsObj) != null) {
throw new IllegalArgumentException("Duplicate metricsName:" + metricsName); throw new IllegalArgumentException("Duplicate metricsName:" +
metricsName);
} }
metricsList.put(metricsName, theMetricsObj);
} }
@ -65,7 +65,7 @@ public synchronized void add(final String metricsName, final MetricsBase theMetr
* @return the metrics if there is one registered by the supplied name. * @return the metrics if there is one registered by the supplied name.
* Returns null if none is registered * Returns null if none is registered
*/ */
public synchronized MetricsBase get(final String metricsName) { public MetricsBase get(final String metricsName) {
return metricsList.get(metricsName); return metricsList.get(metricsName);
} }
@ -74,7 +74,7 @@ public synchronized MetricsBase get(final String metricsName) {
* *
* @return the list of metrics names * @return the list of metrics names
*/ */
public synchronized Collection<String> getKeyList() { public Collection<String> getKeyList() {
return metricsList.keySet(); return metricsList.keySet();
} }
@ -82,7 +82,7 @@ public synchronized Collection<String> getKeyList() {
* *
* @return the list of metrics * @return the list of metrics
*/ */
public synchronized Collection<MetricsBase> getMetricsList() { public Collection<MetricsBase> getMetricsList() {
return metricsList.values(); return metricsList.values();
} }
} }