diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 2417dd7f5cb..61587a51c5e 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -1865,6 +1865,9 @@ Release 0.23.0 - Unreleased MAPREDUCE-3274. Fixed a race condition in MRAppMaster that was causing a task-scheduling deadlock. (Robert Joseph Evans via vinodkv) + MAPREDUCE-3313. Fixed initialization of ClusterMetrics which was failing + TestResourceTrackerService sometimes. (Hitesh Shah via vinodkv) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClusterMetrics.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClusterMetrics.java index 90820c3998e..2a37856d5dd 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClusterMetrics.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ClusterMetrics.java @@ -20,6 +20,8 @@ package org.apache.hadoop.yarn.server.resourcemanager; import static org.apache.hadoop.metrics2.lib.Interns.info; +import java.util.concurrent.atomic.AtomicBoolean; + import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsSystem; @@ -35,6 +37,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeEventType; @Metrics(context="yarn") public class ClusterMetrics { + private static AtomicBoolean isInitialized = new AtomicBoolean(false); + @Metric("# of NMs") MutableGaugeInt numNMs; @Metric("# of decommissioned NMs") MutableCounterInt numDecommissionedNMs; @Metric("# of lost NMs") MutableCounterInt numLostNMs; @@ -48,11 +52,12 @@ public class ClusterMetrics { private static MetricsRegistry registry; public static ClusterMetrics getMetrics() { - if(INSTANCE == null){ + if(!isInitialized.get()){ synchronized (ClusterMetrics.class) { if(INSTANCE == null){ INSTANCE = new ClusterMetrics(); registerMetrics(); + isInitialized.set(true); } } } diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java index e39655a7c8a..d40b7abad8b 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java @@ -31,7 +31,6 @@ import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.exceptions.YarnRemoteException; import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerRequest; @@ -67,8 +66,10 @@ public class TestResourceTrackerService { MockNM nm1 = rm.registerNode("host1:1234", 5120); MockNM nm2 = rm.registerNode("host2:5678", 10240); - int initialMetricCount = ClusterMetrics.getMetrics() - .getNumDecommisionedNMs(); + + ClusterMetrics metrics = ClusterMetrics.getMetrics(); + assert(metrics != null); + int initialMetricCount = metrics.getNumDecommisionedNMs(); HeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));