cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [3/6] git commit: Optimize FD phi calculation patch by jbellis; reviewed by brandonwilliams for CASSANDRA-6386
Date Wed, 20 Nov 2013 18:54:07 GMT
Optimize FD phi calculation
patch by jbellis; reviewed by brandonwilliams for CASSANDRA-6386


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

Branch: refs/heads/trunk
Commit: b3ae77d7baa16673d749c8ab8beae09e0b319c00
Parents: 5f79f53
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Wed Nov 20 12:41:21 2013 -0600
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Wed Nov 20 12:41:21 2013 -0600

----------------------------------------------------------------------
 CHANGES.txt                                     |  4 +++
 .../apache/cassandra/gms/FailureDetector.java   | 12 --------
 src/java/org/apache/cassandra/gms/Gossiper.java |  2 +-
 .../apache/cassandra/gms/IFailureDetector.java  |  6 ----
 .../cassandra/utils/BoundedStatsDeque.java      | 30 +++++++-------------
 .../apache/cassandra/dht/BootStrapperTest.java  |  1 -
 .../cassandra/utils/BoundedStatsDequeTest.java  |  6 ----
 7 files changed, 15 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9c0bc6b..dc56d90 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,7 @@
+1.2.13
+ * Optimize FD phi calculation (CASSANDRA-6386)
+
+
 1.2.12
  * Invalidate row cache when dropping CF (CASSANDRA-6351)
  * add non-jamm path for cached statements (CASSANDRA-6293)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/src/java/org/apache/cassandra/gms/FailureDetector.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/gms/FailureDetector.java b/src/java/org/apache/cassandra/gms/FailureDetector.java
index 26d78ab..e4ffb88 100644
--- a/src/java/org/apache/cassandra/gms/FailureDetector.java
+++ b/src/java/org/apache/cassandra/gms/FailureDetector.java
@@ -177,13 +177,6 @@ public class FailureDetector implements IFailureDetector, FailureDetectorMBean
         return epState != null && epState.isAlive();
     }
 
-    public void clear(InetAddress ep)
-    {
-        ArrivalWindow heartbeatWindow = arrivalSamples.get(ep);
-        if (heartbeatWindow != null)
-            heartbeatWindow.clear();
-    }
-
     public void report(InetAddress ep)
     {
         if (logger.isTraceEnabled())
@@ -312,11 +305,6 @@ class ArrivalWindow
         return arrivalIntervals.mean();
     }
 
-    void clear()
-    {
-        arrivalIntervals.clear();
-    }
-
     // see CASSANDRA-2597 for an explanation of the math at work here.
     double phi(long tnow)
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/src/java/org/apache/cassandra/gms/Gossiper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java
index cbb7d80..545d26b 100644
--- a/src/java/org/apache/cassandra/gms/Gossiper.java
+++ b/src/java/org/apache/cassandra/gms/Gossiper.java
@@ -775,7 +775,7 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean
                 if (!localEndpointState.isAlive())
                 {
                     logger.debug("Clearing interval times for {} due to generation change",
endpoint);
-                    fd.clear(endpoint);
+                    fd.remove(endpoint);
                 }
                 fd.report(endpoint);
                 return;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/src/java/org/apache/cassandra/gms/IFailureDetector.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/gms/IFailureDetector.java b/src/java/org/apache/cassandra/gms/IFailureDetector.java
index 444c100..4e9d528 100644
--- a/src/java/org/apache/cassandra/gms/IFailureDetector.java
+++ b/src/java/org/apache/cassandra/gms/IFailureDetector.java
@@ -38,12 +38,6 @@ public interface IFailureDetector
     public boolean isAlive(InetAddress ep);
 
     /**
-     * Clear any existing interval timings for this endpoint
-     * @param ep
-     */
-    public void clear(InetAddress ep);
-
-    /**
      * This method is invoked by any entity wanting to interrogate the status of an endpoint.
      * In our case it would be the Gossiper. The Failure Detector will then calculate Phi
and
      * deem an endpoint as suspicious or alive as explained in the Hayashibara paper.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java b/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java
index 43d2ce4..c9aa028 100644
--- a/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java
+++ b/src/java/org/apache/cassandra/utils/BoundedStatsDeque.java
@@ -20,17 +20,22 @@ package org.apache.cassandra.utils;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.AtomicDouble;
 
 /**
  * bounded threadsafe deque
  */
 public class BoundedStatsDeque implements Iterable<Double>
 {
-    protected final LinkedBlockingDeque<Double> deque;
+    private final LinkedBlockingDeque<Double> deque;
+    private final AtomicDouble sum;
 
     public BoundedStatsDeque(int size)
     {
         deque = new LinkedBlockingDeque<Double>(size);
+        sum = new AtomicDouble(0);
     }
 
     public Iterator<Double> iterator()
@@ -43,35 +48,20 @@ public class BoundedStatsDeque implements Iterable<Double>
         return deque.size();
     }
 
-    public void clear()
-    {
-        deque.clear();
-    }
-
     public void add(double i)
     {
         if (!deque.offer(i))
         {
-            try
-            {
-                deque.remove();
-            }
-            catch (NoSuchElementException e)
-            {
-                // oops, clear() beat us to it
-            }
+            Double removed = deque.remove();
+            sum.addAndGet(-removed);
             deque.offer(i);
         }
+        sum.addAndGet(i);
     }
 
     public double sum()
     {
-        double sum = 0d;
-        for (Double interval : deque)
-        {
-            sum += interval;
-        }
-        return sum;
+        return sum.get();
     }
 
     public double mean()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/dht/BootStrapperTest.java b/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
index ae7e36c..9931e85 100644
--- a/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
+++ b/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
@@ -198,7 +198,6 @@ public class BootStrapperTest extends SchemaLoader
             public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener
listener) { throw new UnsupportedOperationException(); }
             public void remove(InetAddress ep) { throw new UnsupportedOperationException();
}
             public void forceConviction(InetAddress ep) { throw new UnsupportedOperationException();
}
-            public void clear(InetAddress ep) { throw new UnsupportedOperationException();
}
         };
         s.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(mockFailureDetector));
         s.addRanges(table, Table.open(table).getReplicationStrategy().getPendingAddressRanges(tmd,
myToken, myEndpoint));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b3ae77d7/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java b/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
index 2f5b5d6..7c4b9f2 100644
--- a/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
+++ b/test/unit/org/apache/cassandra/utils/BoundedStatsDequeTest.java
@@ -29,7 +29,6 @@ import org.junit.Test;
 
 public class BoundedStatsDequeTest
 {
-
     @Test
     public void test()
     {
@@ -63,10 +62,5 @@ public class BoundedStatsDequeTest
         assertEquals(size, bsd.size());
         assertEquals(14, bsd.sum(), 0.001d);
         assertEquals(3.5, bsd.mean(), 0.001d);
-
-        //check that it clears properly
-        bsd.clear();
-        assertFalse(bsd.iterator().hasNext());
     }
-
 }


Mime
View raw message