cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1022664 - in /cassandra/trunk/src/java/org/apache/cassandra/locator: AbstractEndpointSnitch.java AbstractNetworkTopologySnitch.java DynamicEndpointSnitch.java IEndpointSnitch.java SimpleSnitch.java
Date Thu, 14 Oct 2010 19:19:37 GMT
Author: jbellis
Date: Thu Oct 14 19:19:36 2010
New Revision: 1022664

URL: http://svn.apache.org/viewvc?rev=1022664&view=rev
Log:
make snitch sortByProximity return void to emphasize that it is sort-in-place.  patch by jbellis

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java
    cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
    cassandra/trunk/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
    cassandra/trunk/src/java/org/apache/cassandra/locator/IEndpointSnitch.java
    cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSnitch.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java?rev=1022664&r1=1022663&r2=1022664&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java Thu
Oct 14 19:19:36 2010
@@ -57,7 +57,7 @@ public abstract class AbstractEndpointSn
     }
 
     public abstract List<InetAddress> getSortedListByProximity(InetAddress address,
Collection<InetAddress> unsortedAddress);
-    public abstract List<InetAddress> sortByProximity(InetAddress address, List<InetAddress>
addresses);
+    public abstract void sortByProximity(InetAddress address, List<InetAddress> addresses);
 
     public int compareEndpoints(InetAddress target, InetAddress a1, InetAddress a2)
     {

Modified: cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java?rev=1022664&r1=1022663&r2=1022664&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
Thu Oct 14 19:19:36 2010
@@ -66,16 +66,15 @@ public abstract class AbstractNetworkTop
      * @param addresses the nodes to sort
      * @return the sorted <tt>List</tt>
      */
-    public List<InetAddress> sortByProximity(final InetAddress address, List<InetAddress>
addresses)
+    public void sortByProximity(final InetAddress address, List<InetAddress> addresses)
     {
         Collections.sort(addresses, new Comparator<InetAddress>()
         {
             public int compare(InetAddress a1, InetAddress a2)
             {
                    return compareEndpoints(address, a1, a2);
-            };
+            }
         });
-        return addresses;
     }
 
     public int compareEndpoints(InetAddress address, InetAddress a1, InetAddress a2)

Modified: cassandra/trunk/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java?rev=1022664&r1=1022663&r2=1022664&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java Thu Oct
14 19:19:36 2010
@@ -118,20 +118,20 @@ public class DynamicEndpointSnitch exten
         return list;
     }
 
-    public List<InetAddress> sortByProximity(final InetAddress address, List<InetAddress>
addresses)
+    public void sortByProximity(final InetAddress address, List<InetAddress> addresses)
     {
         assert address.equals(FBUtilities.getLocalAddress()); // we only know about ourself
         if (BADNESS_THRESHOLD == 0)
         {
-            return sortByProximityWithScore(address, addresses);
+            sortByProximityWithScore(address, addresses);
         }
         else
         {
-            return sortByProximityWithBadness(address, addresses);
+            sortByProximityWithBadness(address, addresses);
         }
     }
 
-    private List<InetAddress> sortByProximityWithScore(final InetAddress address, List<InetAddress>
addresses)
+    private void sortByProximityWithScore(final InetAddress address, List<InetAddress>
addresses)
     {
         Collections.sort(addresses, new Comparator<InetAddress>()
         {
@@ -140,26 +140,27 @@ public class DynamicEndpointSnitch exten
                 return compareEndpoints(address, a1, a2);
             }
         });
-        return addresses;
     }
 
-    private List<InetAddress> sortByProximityWithBadness(final InetAddress address,
List<InetAddress> addresses)
+    private void sortByProximityWithBadness(final InetAddress address, List<InetAddress>
addresses)
     {
         if (addresses.size() < 2)
-            return addresses;
-        List<InetAddress> snitchordered = subsnitch.sortByProximity(address, addresses);
-        Double first = scores.get(snitchordered.get(0));
+            return;
+        subsnitch.sortByProximity(address, addresses);
+        Double first = scores.get(addresses.get(0));
         if (first == null)
-            return snitchordered;
+            return;
         for (InetAddress addr : addresses)
         {
             Double next = scores.get(addr);
             if (next == null)
-                return snitchordered;
+                return;
             if ((first - next) / first > BADNESS_THRESHOLD)
-                return sortByProximityWithScore(address, addresses);
+            {
+                sortByProximityWithScore(address, addresses);
+                return;
+            }
         }
-        return snitchordered;
     }
 
     public int compareEndpoints(InetAddress target, InetAddress a1, InetAddress a2)

Modified: cassandra/trunk/src/java/org/apache/cassandra/locator/IEndpointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/IEndpointSnitch.java?rev=1022664&r1=1022663&r2=1022664&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/IEndpointSnitch.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/IEndpointSnitch.java Thu Oct 14
19:19:36 2010
@@ -51,7 +51,7 @@ public interface IEndpointSnitch
     /**
      * This method will sort the <tt>List</tt> by proximity to the given address.
      */
-    public List<InetAddress> sortByProximity(InetAddress address, List<InetAddress>
addresses);
+    public void sortByProximity(InetAddress address, List<InetAddress> addresses);
 
     /**
      * compares two endpoints in relation to the target endpoint, returning as Comparator.compare
would

Modified: cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSnitch.java?rev=1022664&r1=1022663&r2=1022664&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSnitch.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/locator/SimpleSnitch.java Thu Oct 14 19:19:36
2010
@@ -45,8 +45,7 @@ public class SimpleSnitch extends Abstra
         return new ArrayList<InetAddress>(addresses);
     }
 
-    public List<InetAddress> sortByProximity(final InetAddress address, List<InetAddress>
addresses)
+    public void sortByProximity(final InetAddress address, List<InetAddress> addresses)
     {
-        return addresses;
     }
 }



Mime
View raw message