From 77133fd225df9f65be87ce97b38676d2bab48a71 Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Thu, 25 Feb 2016 09:08:11 -0800 Subject: [PATCH] HBASE-15222 Addendum - Use less contended classes for metrics --- .../apache/hadoop/hbase/util/FastLongHistogram.java | 10 +++------- .../apache/hadoop/metrics2/lib/MutableHistogram.java | 4 +++- .../hadoop/metrics2/lib/MutableRangeHistogram.java | 6 ++++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FastLongHistogram.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FastLongHistogram.java index 78b2bf0e180..9b403d9841b 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FastLongHistogram.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FastLongHistogram.java @@ -310,12 +310,8 @@ public class FastLongHistogram { * Resets the histogram for new counting. */ public FastLongHistogram reset() { - if (this.bins.hasData.get()) { - Bins oldBins = this.bins; - this.bins = new Bins(this.bins, this.bins.counts.length - 3, 0.01, 0.99); - return new FastLongHistogram(oldBins); - } - - return null; + Bins oldBins = this.bins; + this.bins = new Bins(this.bins, this.bins.counts.length - 3, 0.01, 0.99); + return new FastLongHistogram(oldBins); } } diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java index 717e0eec4f9..5b4a2942fa5 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java @@ -63,7 +63,9 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { public synchronized void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { // Get a reference to the old histogram. FastLongHistogram histo = histogram.reset(); - updateSnapshotMetrics(metricsRecordBuilder, histo); + if (histo != null) { + updateSnapshotMetrics(metricsRecordBuilder, histo); + } } protected void updateSnapshotMetrics(MetricsRecordBuilder metricsRecordBuilder, diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java index ac8aee0a8d5..13187af5196 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java @@ -56,8 +56,10 @@ public abstract class MutableRangeHistogram extends MutableHistogram implements public synchronized void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { // Get a reference to the old histogram. FastLongHistogram histo = histogram.reset(); - updateSnapshotMetrics(metricsRecordBuilder, histo); - updateSnapshotRangeMetrics(metricsRecordBuilder, histo); + if (histo != null) { + updateSnapshotMetrics(metricsRecordBuilder, histo); + updateSnapshotRangeMetrics(metricsRecordBuilder, histo); + } } public void updateSnapshotRangeMetrics(MetricsRecordBuilder metricsRecordBuilder,