Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 c884b701d -> 7e05f393f
  refs/heads/cassandra-3.0 8ec609002 -> 51e3660c7
  refs/heads/cassandra-3.11 94a8c777a -> ed45d5eb7
  refs/heads/trunk e1dda71a4 -> 1eaef3f9e


Fix negative mean latency metric

Patch by Per Otterstrom; Reviewed by Chris Lohfink for CASSANDRA-12876


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/7e05f393
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/7e05f393
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/7e05f393

Branch: refs/heads/cassandra-2.2
Commit: 7e05f393f39c90ec0447b1cc893ff46901ae3071
Parents: c884b70
Author: Per Otterstrom <per.otterst...@ericsson.com>
Authored: Wed Jan 18 14:56:01 2017 +0100
Committer: Jeff Jirsa <j...@jeffjirsa.net>
Committed: Sat Feb 11 23:28:35 2017 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../DecayingEstimatedHistogramReservoir.java    |  3 +-
 ...DecayingEstimatedHistogramReservoirTest.java | 31 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/7e05f393/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fc79796..214fe97 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.9
+ * Fix negative mean latency metric (CASSANDRA-12876)
  * Use only one file pointer when creating commitlog segments (CASSANDRA-12539)
  * Fix speculative retry bugs (CASSANDRA-13009)
  * Fix handling of nulls and unsets in IN conditions (CASSANDRA-12981) 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7e05f393/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
 
b/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
index 2458164..2f8bdf8 100644
--- 
a/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
+++ 
b/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java
@@ -352,11 +352,12 @@ public class DecayingEstimatedHistogramReservoir 
implements Reservoir
         public 
EstimatedHistogramReservoirSnapshot(DecayingEstimatedHistogramReservoir 
reservoir)
         {
             final int length = reservoir.decayingBuckets.length();
+            final double rescaleFactor = forwardDecayWeight(clock.getTime());
 
             this.decayingBuckets = new long[length];
 
             for (int i = 0; i < length; i++)
-                this.decayingBuckets[i] = reservoir.decayingBuckets.get(i);
+                this.decayingBuckets[i] = 
Math.round(reservoir.decayingBuckets.get(i) / rescaleFactor);
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7e05f393/test/unit/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoirTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoirTest.java
 
b/test/unit/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoirTest.java
index f2d817f..ef1fed3 100644
--- 
a/test/unit/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoirTest.java
+++ 
b/test/unit/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoirTest.java
@@ -354,6 +354,32 @@ public class DecayingEstimatedHistogramReservoirTest
         }
     }
 
+    @Test
+    public void testDecayingMean()
+    {
+        {
+            TestClock clock = new TestClock();
+
+            DecayingEstimatedHistogramReservoir histogram = new 
DecayingEstimatedHistogramReservoir(DecayingEstimatedHistogramReservoir.DEFAULT_ZERO_CONSIDERATION,
 DecayingEstimatedHistogramReservoir.DEFAULT_BUCKET_COUNT, clock);
+
+            
clock.addMillis(DecayingEstimatedHistogramReservoir.LANDMARK_RESET_INTERVAL_IN_MS
 - 1_000L);
+
+            while (clock.getTime() < 
DecayingEstimatedHistogramReservoir.LANDMARK_RESET_INTERVAL_IN_MS + 1_000L)
+            {
+                clock.addMillis(900);
+                for (int i = 0; i < 1_000_000; i++)
+                {
+                    histogram.update(1000);
+                    histogram.update(2000);
+                    histogram.update(3000);
+                    histogram.update(4000);
+                    histogram.update(5000);
+                }
+                assertEquals(3000D, histogram.getSnapshot().getMean(), 500D);
+            }
+        }
+    }
+
     private void assertEstimatedQuantile(long expectedValue, double 
actualValue)
     {
         assertTrue("Expected at least [" + expectedValue + "] but actual is [" 
+ actualValue + "]", actualValue >= expectedValue);
@@ -363,6 +389,11 @@ public class DecayingEstimatedHistogramReservoirTest
     public class TestClock extends Clock {
         private long tick = 0;
 
+        public void addMillis(long millis)
+        {
+            tick += millis * 1_000_000L;
+        }
+
         public void addSeconds(long seconds)
         {
             tick += seconds * 1_000_000_000L;

Reply via email to