cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject svn commit: r985723 - in /cassandra/branches/cassandra-0.6: src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
Date Sun, 15 Aug 2010 17:59:09 GMT
Author: brandonwilliams
Date: Sun Aug 15 17:59:09 2010
New Revision: 985723

URL: http://svn.apache.org/viewvc?rev=985723&view=rev
Log:
fall back to subsnitch on score equality as well as no score at all.  Patch by jbellis and
brandonwilliams, reviewed by brandonwilliams for CASSANDRA-981

Modified:
    cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
    cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java

Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java?rev=985723&r1=985722&r2=985723&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
(original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
Sun Aug 15 17:59:09 2010
@@ -115,7 +115,7 @@ public class DynamicEndpointSnitch exten
 
     public List<InetAddress> sortByProximity(final InetAddress address, List<InetAddress>
addresses)
     {
-        assert address == FBUtilities.getLocalAddress(); // we only know about ourself
+        assert address.equals(FBUtilities.getLocalAddress()); // we only know about ourself
         Collections.sort(addresses, new Comparator<InetAddress>()
         {
             public int compare(InetAddress a1, InetAddress a2)
@@ -131,14 +131,12 @@ public class DynamicEndpointSnitch exten
         Double scored1 = scores.get(a1);
         Double scored2 = scores.get(a2);
 
-        if (scored1 == null || scored2 == null)
+        if (scored1 == null || scored2 == null || scored1.equals(scored2))
             return subsnitch.compareEndpoints(target, a1, a2);
-        if (scored1.equals(scored2))
-            return 0;
         if (scored1 < scored2)
-            return 1;
-        else
             return -1;
+        else
+            return 1;
     }
 
     public void receiveTiming(InetAddress host, Double latency) // this is cheap

Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java?rev=985723&r1=985722&r2=985723&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
(original)
+++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java
Sun Aug 15 17:59:09 2010
@@ -25,9 +25,6 @@ import java.util.ArrayList;
 
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-import org.apache.cassandra.locator.DynamicEndpointSnitch;
-import org.apache.cassandra.locator.SimpleSnitch;
 import org.apache.cassandra.utils.FBUtilities;
 
 public class DynamicEndpointSnitchTest
@@ -35,7 +32,8 @@ public class DynamicEndpointSnitchTest
     @Test
     public void testSnitch() throws UnknownHostException, InterruptedException
     {
-        DynamicEndpointSnitch dsnitch = new DynamicEndpointSnitch(new SimpleSnitch());
+        int sleeptime = 150;
+        DynamicEndpointSnitch dsnitch = new DynamicEndpointSnitch(new EndPointSnitch());
         InetAddress self = FBUtilities.getLocalAddress();
         ArrayList<InetAddress> order = new ArrayList<InetAddress>();
         InetAddress host1 = InetAddress.getByName("127.0.0.1");
@@ -50,34 +48,31 @@ public class DynamicEndpointSnitchTest
             dsnitch.receiveTiming(host3, 1.0);
         }
 
-        Thread.sleep(1500);
+        Thread.sleep(sleeptime);
 
         order.add(host1);
         order.add(host2);
         order.add(host3);
-
         assert dsnitch.getSortedListByProximity(self, order).equals(order);
 
         // make host1 a little worse
         dsnitch.receiveTiming(host1, 2.0);
-        Thread.sleep(1500);
-        order.clear();
+        Thread.sleep(sleeptime);
 
+        order.clear();
         order.add(host2);
         order.add(host3);
         order.add(host1);
-
         assert dsnitch.getSortedListByProximity(self, order).equals(order);
 
-        // make host2 a little worse
+        // make host2 as bad as host1
         dsnitch.receiveTiming(host2, 2.0);
-        Thread.sleep(1500);
-        order.clear();
+        Thread.sleep(sleeptime);
 
+        order.clear();
         order.add(host3);
-        order.add(host2);
         order.add(host1);
-
+        order.add(host2);
         assert dsnitch.getSortedListByProximity(self, order).equals(order);
 
         // make host3 the worst
@@ -85,25 +80,25 @@ public class DynamicEndpointSnitchTest
         {
             dsnitch.receiveTiming(host3, 2.0);
         }
-        Thread.sleep(1500);
-        order.clear();
+        Thread.sleep(sleeptime);
 
-        order.add(host2);
+        order.clear();
         order.add(host1);
+        order.add(host2);
         order.add(host3);
+        assert dsnitch.getSortedListByProximity(self, order).equals(order);
 
         // make host3 equal to the others
         for (int i = 0; i < 2; i++)
         {
             dsnitch.receiveTiming(host3, 1.0);
         }
-        Thread.sleep(1500);
-        order.clear();
+        Thread.sleep(sleeptime);
 
+        order.clear();
         order.add(host1);
         order.add(host2);
         order.add(host3);
-
         assert dsnitch.getSortedListByProximity(self, order).equals(order);
     }
 }



Mime
View raw message