hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iva...@apache.org
Subject svn commit: r1553557 - in /hadoop/common/branches/branch-1: CHANGES.txt src/core/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java src/test/org/apache/hadoop/metrics2/impl/TestMetricsSourceAdapter.java
Date Thu, 26 Dec 2013 19:20:39 GMT
Author: ivanmi
Date: Thu Dec 26 19:20:39 2013
New Revision: 1553557

URL: http://svn.apache.org/r1553557
Log:
HADOOP-10090. Jobtracker metrics not updated properly after execution of a mapreduce job.
Contributed by Ivan Mitic.

Added:
    hadoop/common/branches/branch-1/src/test/org/apache/hadoop/metrics2/impl/TestMetricsSourceAdapter.java
Modified:
    hadoop/common/branches/branch-1/CHANGES.txt
    hadoop/common/branches/branch-1/src/core/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java

Modified: hadoop/common/branches/branch-1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/CHANGES.txt?rev=1553557&r1=1553556&r2=1553557&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1/CHANGES.txt Thu Dec 26 19:20:39 2013
@@ -169,6 +169,9 @@ Release 1.3.0 - unreleased
     HADOOP-10142. Avoid groups lookup for unprivileged users such as "dr.who"
     (vinay, backported by Xi Fang via cnauroth)
 
+    HADOOP-10090. Jobtracker metrics not updated properly after execution of
+    a mapreduce job (ivanmi)
+
 Release 1.2.2 - unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java?rev=1553557&r1=1553556&r2=1553557&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
(original)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
Thu Dec 26 19:20:39 2013
@@ -343,7 +343,7 @@ public class MetricsSystemImpl implement
   private void snapshotMetrics(MetricsSourceAdapter sa,
                                MetricsBufferBuilder bufferBuilder) {
     long startTime = System.currentTimeMillis();
-    bufferBuilder.add(sa.name(), sa.getMetrics(metricsBuilder, false));
+    bufferBuilder.add(sa.name(), sa.getMetrics(metricsBuilder, true));
     metricsBuilder.clear();
     snapshotStat.add(System.currentTimeMillis() - startTime);
     LOG.debug("Snapshotted source "+ sa.name());

Added: hadoop/common/branches/branch-1/src/test/org/apache/hadoop/metrics2/impl/TestMetricsSourceAdapter.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/test/org/apache/hadoop/metrics2/impl/TestMetricsSourceAdapter.java?rev=1553557&view=auto
==============================================================================
--- hadoop/common/branches/branch-1/src/test/org/apache/hadoop/metrics2/impl/TestMetricsSourceAdapter.java
(added)
+++ hadoop/common/branches/branch-1/src/test/org/apache/hadoop/metrics2/impl/TestMetricsSourceAdapter.java
Thu Dec 26 19:20:39 2013
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.metrics2.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.lib.AbstractMetricsSource;
+import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
+import org.junit.Test;
+
+public class TestMetricsSourceAdapter {
+
+  @Test
+  public void testGetMetricsAndJmx() throws Exception {
+    // create test source with a single metric counter of value 0
+    TestSource source = new TestSource("test");
+    List<MetricsTag> injectedTags = new ArrayList<MetricsTag>();
+    MetricsSourceAdapter sa = new MetricsSourceAdapter(
+        "test", "test", "test desc", source, injectedTags, null, null, 1);
+
+    // all metrics are initially assumed to have changed
+    MetricsBuilderImpl builder = new MetricsBuilderImpl();
+    Iterable<MetricsRecordImpl> metricsRecords = sa.getMetrics(builder, true);
+
+    // Validate getMetrics and JMX initial values
+    MetricsRecordImpl metricsRecord = metricsRecords.iterator().next();
+    assertEquals(0L,
+        metricsRecord.metrics().iterator().next().value().longValue());
+
+    Thread.sleep(100); // skip JMX cache TTL
+    assertEquals(0L, (Number)sa.getAttribute("c1"));
+
+    // change metric value
+    source.incrementCnt();
+
+    // validate getMetrics and JMX
+    builder = new MetricsBuilderImpl();
+    metricsRecords = sa.getMetrics(builder, true);
+    metricsRecord = metricsRecords.iterator().next();
+    assertTrue(metricsRecord.metrics().iterator().hasNext());
+    Thread.sleep(100); // skip JMX cache TTL
+    assertEquals(1L, (Number)sa.getAttribute("c1"));
+  }
+
+  private static class TestSource extends AbstractMetricsSource {
+    final MetricMutableCounterLong c1;
+
+    TestSource(String name) {
+      super(name);
+      registry.setContext("test");
+      c1 = registry.newCounter("c1", "c1 desc", 0L);
+    }
+
+    public void incrementCnt() {
+      c1.incr();
+    }
+  }
+}



Mime
View raw message