cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [05/14] git commit: Fix LatencyMetrics returning infinity.
Date Wed, 02 Apr 2014 22:00:41 GMT
Fix LatencyMetrics returning infinity.

Patch by Nick Bailey, reviewed by Lyuben Todorov for CASSANDRA-6920


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

Branch: refs/heads/cassandra-2.1
Commit: 3ca740119e7b402a453a2fb43ee904a0ee313ff0
Parents: a4d7e22
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Wed Apr 2 16:54:40 2014 -0500
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Wed Apr 2 16:54:40 2014 -0500

----------------------------------------------------------------------
 .../apache/cassandra/metrics/LatencyMetrics.java    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3ca74011/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
index 01ba997..c2c48f2 100644
--- a/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
+++ b/src/java/org/apache/cassandra/metrics/LatencyMetrics.java
@@ -90,8 +90,11 @@ public class LatencyMetrics
 
     public void addMicro(long micros)
     {
-        latency.update(micros, TimeUnit.MICROSECONDS);
-        totalLatency.inc(micros);
+        synchronized (this)
+        {
+            latency.update(micros, TimeUnit.MICROSECONDS);
+            totalLatency.inc(micros);
+        }
         totalLatencyHistogram.add(micros);
         recentLatencyHistogram.add(micros);
     }
@@ -105,8 +108,13 @@ public class LatencyMetrics
     @Deprecated
     public double getRecentLatency()
     {
-        long ops = latency.count();
-        long n = totalLatency.count();
+        long ops = 0;
+        long n = 0;
+        synchronized (this)
+        {
+            ops = latency.count();
+            n = totalLatency.count();
+        }
         try
         {
             return ((double) n - lastLatency) / (ops - lastOpCount);


Mime
View raw message