cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1176712 - in /cassandra/branches/cassandra-0.8: ./ src/java/org/apache/cassandra/locator/
Date Wed, 28 Sep 2011 04:11:19 GMT
Author: jbellis
Date: Wed Sep 28 04:11:19 2011
New Revision: 1176712

URL: http://svn.apache.org/viewvc?rev=1176712&view=rev
Log:
Keep SimpleSnitch proximity ordering unchanged from what the Strategy generates, as intended
patch by slebresne; reviewed by jbellis for CASSANDRA-3262

Modified:
    cassandra/branches/cassandra-0.8/CHANGES.txt
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/SimpleSnitch.java

Modified: cassandra/branches/cassandra-0.8/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/CHANGES.txt?rev=1176712&r1=1176711&r2=1176712&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.8/CHANGES.txt Wed Sep 28 04:11:19 2011
@@ -10,6 +10,9 @@
  * Fix FD leak when internode encryption is enabled (CASSANDRA-3257)
  * FBUtilities.hexToBytes(String) to throw NumberFormatException when string
    contains non-hex characters (CASSANDRA-3231)
+ * Keep SimpleSnitch proximity ordering unchanged from what the Strategy
+   generates, as intended (CASSANDRA-3262)
+
 
 0.8.6
  * revert CASSANDRA-2388

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java?rev=1176712&r1=1176711&r2=1176712&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractEndpointSnitch.java
Wed Sep 28 04:11:19 2011
@@ -20,8 +20,7 @@
 package org.apache.cassandra.locator;
 
 import java.net.InetAddress;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,13 +28,35 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractEndpointSnitch implements IEndpointSnitch
 {
     private static final Logger logger = LoggerFactory.getLogger(AbstractEndpointSnitch.class);
-    
-    public abstract List<InetAddress> getSortedListByProximity(InetAddress address,
Collection<InetAddress> unsortedAddress);
-    public abstract void sortByProximity(InetAddress address, List<InetAddress> addresses);
+    public abstract int compareEndpoints(InetAddress target, InetAddress a1, InetAddress
a2);
 
-    public int compareEndpoints(InetAddress target, InetAddress a1, InetAddress a2)
+    /**
+     * Sorts the <tt>Collection</tt> of node addresses by proximity to the given
address
+     * @param address the address to sort by proximity to
+     * @param unsortedAddress the nodes to sort
+     * @return a new sorted <tt>List</tt>
+     */
+    public List<InetAddress> getSortedListByProximity(InetAddress address, Collection<InetAddress>
unsortedAddress)
     {
-        return a1.getHostAddress().compareTo(a2.getHostAddress());
+        List<InetAddress> preferred = new ArrayList<InetAddress>(unsortedAddress);
+        sortByProximity(address, preferred);
+        return preferred;
+    }
+
+    /**
+     * Sorts the <tt>List</tt> of node addresses, in-place, by proximity to the
given address
+     * @param address the address to sort the proximity by
+     * @param addresses the nodes to sort
+     */
+    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);
+            }
+        });
     }
 
     public void gossiperStarting()

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java?rev=1176712&r1=1176711&r2=1176712&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/AbstractNetworkTopologySnitch.java
Wed Sep 28 04:11:19 2011
@@ -47,36 +47,6 @@ public abstract class AbstractNetworkTop
      */
     abstract public String getDatacenter(InetAddress endpoint);
 
-    /**
-     * Sorts the <tt>Collection</tt> of node addresses by proximity to the given
address
-     * @param address the address to sort by proximity to
-     * @param addresses the nodes to sort
-     * @return a new sorted <tt>List</tt>
-     */
-    public List<InetAddress> getSortedListByProximity(final InetAddress address, Collection<InetAddress>
addresses)
-    {
-        List<InetAddress> preferred = new ArrayList<InetAddress>(addresses);
-        sortByProximity(address, preferred);
-        return preferred;
-    }
-
-    /**
-     * Sorts the <tt>List</tt> of node addresses by proximity to the given address
-     * @param address the address to sort the proximity by
-     * @param addresses the nodes to sort
-     * @return the sorted <tt>List</tt>
-     */
-    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);
-            }
-        });
-    }
-
     public int compareEndpoints(InetAddress address, InetAddress a1, InetAddress a2)
     {
         if (address.equals(a1) && !address.equals(a2))

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java?rev=1176712&r1=1176711&r2=1176712&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/DynamicEndpointSnitch.java
Wed Sep 28 04:11:19 2011
@@ -129,6 +129,7 @@ public class DynamicEndpointSnitch exten
         return list;
     }
 
+    @Override
     public void sortByProximity(final InetAddress address, List<InetAddress> addresses)
     {
         assert address.equals(FBUtilities.getLocalAddress()); // we only know about ourself
@@ -144,13 +145,7 @@ public class DynamicEndpointSnitch exten
 
     private void sortByProximityWithScore(final InetAddress address, List<InetAddress>
addresses)
     {
-        Collections.sort(addresses, new Comparator<InetAddress>()
-        {
-            public int compare(InetAddress a1, InetAddress a2)
-            {
-                return compareEndpoints(address, a1, a2);
-            }
-        });
+        super.sortByProximity(address, addresses);
     }
 
     private void sortByProximityWithBadness(final InetAddress address, List<InetAddress>
addresses)

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/SimpleSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/SimpleSnitch.java?rev=1176712&r1=1176711&r2=1176712&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/SimpleSnitch.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/locator/SimpleSnitch.java
Wed Sep 28 04:11:19 2011
@@ -39,13 +39,17 @@ public class SimpleSnitch extends Abstra
     {
         return "datacenter1";
     }
-    
-    public List<InetAddress> getSortedListByProximity(final InetAddress address, Collection<InetAddress>
addresses)
+
+    @Override
+    public void sortByProximity(final InetAddress address, List<InetAddress> addresses)
     {
-        return new ArrayList<InetAddress>(addresses);
+        // Optimization to avoid walking the list
     }
 
-    public void sortByProximity(final InetAddress address, List<InetAddress> addresses)
+    public int compareEndpoints(InetAddress target, InetAddress a1, InetAddress a2)
     {
+        // Making all endpoints equal ensures we won't change the original ordering (since
+        // Collections.sort is guaranteed to be stable)
+        return 0;
     }
 }



Mime
View raw message