cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r834945 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: locator/AbstractReplicationStrategy.java service/StorageService.java
Date Wed, 11 Nov 2009 16:23:42 GMT
Author: jbellis
Date: Wed Nov 11 16:23:41 2009
New Revision: 834945

URL: http://svn.apache.org/viewvc?rev=834945&view=rev
Log:
simplify getChangedRangesForLeaving.  patch by Jaakko Laine; reviewed by jbellis for CASSANDRA-435

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java?rev=834945&r1=834944&r2=834945&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
Wed Nov 11 16:23:41 2009
@@ -206,32 +206,6 @@
         return getAddressRanges(temp).get(pendingAddress);
     }
 
-    /**
-     * @param endpoint the endpoint leaving
-     * @return a map of where the endpoint's current ranges get sent
-     */
-    public Multimap<Range, InetAddress> getRangeAddressesAfterLeaving(InetAddress endpoint)
-    {
-        TokenMetadata metadataAfterLeaving = tokenMetadata_.cloneWithoutPending();
-        metadataAfterLeaving.removeEndpoint(endpoint);
-        Multimap<Range, InetAddress> rangesAfterLeaving = getRangeAddresses(metadataAfterLeaving);
-
-        Multimap<Range, InetAddress> map = HashMultimap.create();
-        for (Range range : getAddressRanges().get(endpoint))
-        {
-            for (Range newRange : rangesAfterLeaving.keySet())
-            {
-                if (newRange.contains(range))
-                {
-                    map.putAll(range, rangesAfterLeaving.get(newRange));
-                    break;
-                }
-            }
-        }
-
-        return map;
-    }
-
     public void removeObsoletePendingRanges()
     {
         Multimap<InetAddress, Range> ranges = getAddressRanges();

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=834945&r1=834944&r2=834945&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java Wed
Nov 11 16:23:41 2009
@@ -396,34 +396,38 @@
 
     private Multimap<Range, InetAddress> getChangedRangesForLeaving(InetAddress endpoint)
     {
-        Multimap<Range, InetAddress> newRangeAddresses = replicationStrategy_.getRangeAddressesAfterLeaving(endpoint);
+        // First get all ranges the leaving endpoint is responsible for
+        Collection<Range> ranges = getRangesForEndPoint(endpoint);
+
         if (logger_.isDebugEnabled())
-            logger_.debug("leaving node ranges are [" + StringUtils.join(newRangeAddresses.keySet(),
", ") + "]");
+            logger_.debug("leaving node ranges are [" + StringUtils.join(ranges, ", ") +
"]");
+
+        Map<Range, ArrayList<InetAddress>> currentReplicaEndpoints = new HashMap<Range,
ArrayList<InetAddress>>();
+
+        // Find (for each range) all nodes that store replicas for these ranges as well
+        for (Range range : ranges)
+            currentReplicaEndpoints.put(range, replicationStrategy_.getNaturalEndpoints(range.right(),
tokenMetadata_));
+
+        TokenMetadata temp = tokenMetadata_.cloneWithoutPending();
+        temp.removeEndpoint(endpoint);
+
         Multimap<Range, InetAddress> changedRanges = HashMultimap.create();
-        for (final Range range : newRangeAddresses.keySet())
+
+        // Go through the ranges and for each range check who will be
+        // storing replicas for these ranges when the leaving endpoint
+        // is gone. Whoever is present in newReplicaEndpoins list, but
+        // not in the currentReplicaEndpoins list, will be needing the
+        // range.
+        for (Range range : ranges)
         {
+            ArrayList<InetAddress> newReplicaEndpoints = replicationStrategy_.getNaturalEndpoints(range.right(),
temp);
+            newReplicaEndpoints.removeAll(currentReplicaEndpoints.get(range));
             if (logger_.isDebugEnabled())
-                logger_.debug("considering Range " + range);
-            for (InetAddress newEndpoint : newRangeAddresses.get(range))
-            {
-                boolean alreadyReplicatesRange = false;
-                for (Range existingRange : getRangesForEndPoint(newEndpoint))
-                {
-                    if (existingRange.contains(range))
-                    {
-                        alreadyReplicatesRange = true;
-                        break;
-                    }
-                }
-                if (!alreadyReplicatesRange)
-                {
-                    if (logger_.isDebugEnabled())
-                        logger_.debug(newEndpoint + " needs pendingrange " + range);
-                    changedRanges.put(range, newEndpoint);
-                }
-            }
+                logger_.debug("adding pending range " + range + " to endpoints " + StringUtils.join(newReplicaEndpoints,
", "));
+            changedRanges.putAll(range, newReplicaEndpoints);
         }
-        return changedRanges;        
+
+        return changedRanges;
     }
 
     private void updateLeavingRanges(final InetAddress endpoint)



Mime
View raw message