From f59b698fc99211c010d569e7f71555183dfc29f1 Mon Sep 17 00:00:00 2001 From: Junping Du Date: Wed, 4 Feb 2015 19:10:52 -0800 Subject: [PATCH] HADOOP-10062. race condition in MetricsSystemImpl#publishMetricsNow that causes incorrect results. (Contributed by Sangjin Lee) (cherry picked from commit 0b567f424673b5cea1c3bc23b2bd268ef6b7625f) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java | 2 +- .../org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 05346f22f70..1eef93ee616 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -485,6 +485,9 @@ Release 2.7.0 - UNRELEASED HADOOP-11549. flaky test detection tool failed to handle special control characters in test result. (Yongjun Zhang via aajisaka) + HADOOP-10062. race condition in MetricsSystemImpl#publishMetricsNow that + causes incorrect results. (Sangjin Lee via junping_du) + Release 2.6.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java index 4507e357957..b7660e5711c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java @@ -387,7 +387,7 @@ public class MetricsSystemImpl extends MetricsSystem implements MetricsSource { * Requests an immediate publish of all metrics from sources to sinks. */ @Override - public void publishMetricsNow() { + public synchronized void publishMetricsNow() { if (sinks.size() > 0) { publishMetrics(sampleMetrics(), true); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java index d59e80b5820..4c2ebc8e0e8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java @@ -190,7 +190,7 @@ public class TestMetricsSystemImpl { threads[i] = new Thread(new Runnable() { private boolean safeAwait(int mySource, CyclicBarrier barrier) { try { - barrier1.await(2, TimeUnit.SECONDS); + barrier.await(2, TimeUnit.SECONDS); } catch (InterruptedException e) { results[mySource] = "Interrupted"; return false;