cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaa...@apache.org
Subject svn commit: r901930 - /incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
Date Fri, 22 Jan 2010 00:00:07 GMT
Author: jaakko
Date: Fri Jan 22 00:00:07 2010
New Revision: 901930

URL: http://svn.apache.org/viewvc?rev=901930&view=rev
Log:
Ignore non-members in hinted location search. Find hint location based on proximity, not token
order. Patch by jaakko, reviewed by jbellis. CASSANDRA-722

Modified:
    incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java

Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java?rev=901930&r1=901929&r2=901930&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
Fri Jan 22 00:00:07 2010
@@ -29,9 +29,11 @@
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.gms.FailureDetector;
+import org.apache.cassandra.gms.Gossiper;
 import org.apache.cassandra.service.IResponseResolver;
 import org.apache.cassandra.service.QuorumResponseHandler;
 import org.apache.cassandra.service.WriteResponseHandler;
+import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
 
 /**
@@ -114,6 +116,9 @@
         Set<InetAddress> usedEndpoints = new HashSet<InetAddress>();
         Map<InetAddress, InetAddress> map = new HashMap<InetAddress, InetAddress>();
 
+        IEndPointSnitch endPointSnitch = StorageService.instance().getEndPointSnitch();
+        Set<InetAddress> liveNodes = Gossiper.instance().getLiveMembers();
+
         for (InetAddress ep : targets)
         {
             if (FailureDetector.instance().isAlive(ep))
@@ -123,25 +128,21 @@
             }
             else
             {
+                // Ignore targets that have died when bootstrapping
+                if (!tokenMetadata_.isMember(ep))
+                    continue;
+
                 // find another endpoint to store a hint on.  prefer endpoints that aren't
already in use
                 InetAddress hintLocation = null;
-                List tokens = tokenMetadata_.sortedTokens();
-                Token token = tokenMetadata_.getToken(ep);
-                int index = Collections.binarySearch(tokens, token);
-                if (index < 0)
-                {
-                    index = (index + 1) * (-1);
-                    if (index >= tokens.size()) // handle wrap
-                        index = 0;
-                }
-                int totalNodes = tokens.size();
-                int startIndex = (index + 1) % totalNodes;
-                for (int i = startIndex, count = 1; count < totalNodes; ++count, i = (i
+ 1) % totalNodes)
+                List<InetAddress> preferred = endPointSnitch.getSortedListByProximity(ep,
liveNodes);
+
+                for (InetAddress hintCandidate : preferred)
                 {
-                    InetAddress tmpEndPoint = tokenMetadata_.getEndPoint((Token) tokens.get(i));
-                    if (FailureDetector.instance().isAlive(tmpEndPoint) && !targets.contains(tmpEndPoint)
&& !usedEndpoints.contains(tmpEndPoint))
+                    if (!targets.contains(hintCandidate)
+                        && !usedEndpoints.contains(hintCandidate)
+                        && tokenMetadata_.isMember(hintCandidate))
                     {
-                        hintLocation = tmpEndPoint;
+                        hintLocation = hintCandidate;
                         break;
                     }
                 }



Mime
View raw message